Understanding the value of Spring-1.15 to Spel from the beginning (2)-contrast value

Source: Internet
Author: User

In this chapter we discuss the value of the Spel value.

1.domain

Oven class: (Added Bigornot property)

Package Com.raylee.my_new_spring.my_new_spring.ch01.topic_1_18;public class Oven {private String name = "";p rivate Double size = 0;private Boolean bigornot = False;public Boolean isbigornot () {return bigornot;} public void Setbigornot (Boolean bigornot) {this.bigornot = Bigornot;} Public double GetSize () {return size;} public void SetSize (double size) {this.size = size;} @Overridepublic String toString () {return name + "Size:" + size;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;}}


Chef class: (Increase the method of checking the oven)

Package Com.raylee.my_new_spring.my_new_spring.ch01.topic_1_18;public class Chief {private String name = "";p rivate Oven oven;public void Checkoven () {if (Getoven (). Isbigornot ()) {System.out.println (Getoven ()); SYSTEM.OUT.PRINTLN ("oven is big");} else {System.out.println (Getoven ()); SYSTEM.OUT.PRINTLN ("Oven is not big");}} Public String GetName () {return name;} Public Oven Getoven () {return Oven;} public void SetName (String name) {this.name = name;} public void Setoven (Oven Oven) {this.oven = Oven;}}



2. Test class: (replace the oven with a check oven)

Package Com.raylee.my_new_spring.my_new_spring.ch01.topic_1_18;import Org.junit.test;import Org.junit.runner.runwith;import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.context.applicationcontext;import org.springframework.test.context.ContextConfiguration; Import Org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith (Springjunit4classrunner.class) @ Contextconfiguration (locations = {"/com/raylee/my_new_spring/my_new_spring/ch01/topic_1_18/ Applicationcontext-test.xml "}) public class Chieftest {@Autowiredprivate ApplicationContext applicationcontext;@ testpublic void Testchief () {Chief Jack = (Chief) Applicationcontext.getbean ("Jack"); Jack.checkoven (); Chief Mike = (Chief) Applicationcontext.getbean ("Mike"); Mike.checkoven (); Chief Rose = (chief) Applicationcontext.getbean ("Rose"); Rose.checkoven ();}}



3. Configuration file: (Focus)

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: context= "Http://www.springframework.org/schema/context" xmlns:p= "http://www.springframework.org/schema/p" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns:aop= " Http://www.springframework.org/schema/aop "xsi:schemalocation=" Http://www.springframework.org/schema/beans http ://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/context http ://www.springframework.org/schema/context/spring-context-3.1.xsdhttp://www.springframework.org/schema/tx http:/ /www.springframework.org/schema/tx/spring-tx-3.1.xsdhttp://www.springframework.org/schema/util/HTTP WWW.SPRINGFRAMEWORK.ORG/SCHEMA/UTIL/SPRING-UTIL-3.1.XSDHTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/DATA/JPA/HTTP Www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsdhttp://www.springframework.org/schema/beans/HTTP Www.sprinGframework.org/schema/beans/spring-beans.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP/HTTP Www.springframework.org/schema/aop/spring-aop.xsd "><bean id=" Smalloven "class=" com.raylee.my_new_spring.my _new_spring.ch01.topic_1_18.oven "P:name=" Smalloven "p:size=" #{2*5} "p:bigornot=" #{10 >= 8} "/><bean id=" Midoven "class=" Com.raylee.my_new_spring.my_new_spring.ch01.topic_1_18.Oven "p:name=" Midoven "p:size=" #{t ( Java.lang.Math). PI*4} "p:bigornot=" #{smalloven.getsize () Lt 8} "/><bean id=" Bigoven "class=" Com.raylee.my_new_spring.my_new_ Spring.ch01.topic_1_18.Oven "P:name=" Bigoven "p:size=" #{smalloven.getsize () "p:bigornot=" #{midoven.getsize () GT 8} "/><bean id=" Mike "class=" Com.raylee.my_new_spring.my_new_spring.ch01.topic_1_18.Chief "P:name=" Mike "> <property name= "oven" ref= "Smalloven"/></bean><bean id= "Jack" class= "Com.raylee.my_new_spring.my_ New_spring.ch01.topic_1_18.Chief "P:name=" Jack "><property name=" oven "ref=" Midoven "/&GT;&LT;/BEAN&GT;<bean id= "Rose" class= "Com.raylee.my_new_spring.my_new_spring.ch01.topic_1_18.Chief" P:name= "Rose" >< Property name= "Oven" ref= "Bigoven"/></bean></beans>


The focus of the configuration file is to look at the P:bigornot property inside the oven, where we can compare two values by contrast to produce the final result.

Test output:

Midoven size:12.566370614359172
Oven is not big
Smalloven size:10.0
Oven is big
Bigoven size:40.0
Oven is big

We just showed the part above, it has:> greater than < less than >= is equal to <= less than equals = = equals, everyone behind can try each.


Summary: In this chapter we discuss the value of the Spel values.


Catalog: http://blog.csdn.net/raylee2007/article/details/50611627

My github:https://github.com/raylee2015/my_new_spring.


Understanding the value of Spring-1.15 to Spel from the beginning (2)-contrast value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.