spring3.0学习笔记(3)---SpEL表达式2

简介: spring3.0学习笔记(3)---SpEL表达式2
Java代码  
例一:使用符号  
//evaluates to true  
boolean trueValue=parser.parseExpression("2==2").getValue(Boolean.class);  
//evaluates to false  
boolean falseValue=parser.parseExpression("2<-5.0").getValue(Boolean.class);  
//evaluates to true  
boolean trueValue=parser.parseExpression("'black'<'block'").getValue(Boolean.class); //字符串的比较  
例二:判断是否是类中的一个实例  
//evaluates to false  
boolean falseValue=parser.parseExpression("'xyz'  instanceofT(int)").getValue(Boolean.class);  
例三:和正则表达式结合  
//evaluates to true  
boolean trueValue = parser.parseExpression("'5.00'matches'^-?\\d+\\.\\d{2})?$'").getValue(Boolean.class);  
//evaluates to false  
boolean falseValue = parser.parseExpression("'5.0067'matches'^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);  
例四:逻辑运算符  
//--AND--  
//evaluates to false  
boolean falseValue=parser.parseExpression("true and false").getValue(Boolean.class);//取后者  
//evaluates to true  
String expression= "isMember('NikolaTesla')  and  isMember('MihajloPupin')";  
boolean trueValue=parser.parseExpression(expression).getValue(societyContext,Boolean.class);  
//--OR--  
//evaluates to  true  
boolean trueValue=parser.parseExpression("true  or   false").getValue(Boolean.class);  
//evaluates  to  true  
String  expression= "isMember('Nikola Tesla')  or  isMember('Albert Einstien')";  
boolean trueValue=parser.parseExpression(expression).getValue(societyContext,Boolean.class);  
//--NOT--  
//evaluates to false  
boolean falseValue=parser.parseExpression(" !true").getValue(Boolean.class);  
//--AND  and  NOT--  
String expression= "isMember('NikolaTesla') and !isMember('MihajloPupin')";  
boolean falseValue=parser.parseExpression(expression).getValue(societyContext,Boolean.class);  
例五:算术运算符  
//Addition  
int two=parser.parseExpression("1+1").getValue(Integer.class); //2  
String testString=parser.parseExpression(" 'test'+'string' ").getValue(String.class); //'teststring'  
//Subtraction  
int four=parser.parseExpression("1-3").getValue(Integer.class); //4  
double d=parser.parseExpression("1000.00-1e4").getValue(Double.class); //-9000  
//Multiplication  
int six=parser.parseExpression("-2*-3").getValue(Integer.class); //6  
double twentyFour=parser.parseExpression("2.0*3e0*4").getValue(Double.class); //24.0  
//Division  
int minusTwo=parser.parseExpression("6/-3").getValue(Integer.class); //-2  
double one=parser.parseExpression("8.0/4e0/2").getValue(Double.class); //1.0  
//Modulus  
int three=parser.parseExpression("7%4").getValue(Integer.class); //3  
int one=parser.parseExpression("8/5%2").getValue(Integer.class); //1  
//Operator precedence  
int minusTwentyOne=parser.parseExpression("1+2-3*8").getValue(Integer.class); //-21  
相关文章
|
4月前
|
Java Maven Spring
【Spring】EL表达式失效的问题(添加 isELIgnored)
【Spring】EL表达式失效的问题(添加 isELIgnored)
|
20天前
|
安全 Java 数据安全/隐私保护
【深入浅出Spring原理及实战】「EL表达式开发系列」深入解析SpringEL表达式理论详解与实际应用
【深入浅出Spring原理及实战】「EL表达式开发系列」深入解析SpringEL表达式理论详解与实际应用
43 1
|
2月前
|
XML 前端开发 Java
深入理解Spring EL表达式的高级功能
深入理解Spring EL表达式的高级功能
67 1
|
2月前
|
XML 前端开发 Java
掌握Spring EL表达式的基础知识
掌握Spring EL表达式的基础知识
38 1
|
3月前
|
XML Java 数据格式
spring AOP切入点execution表达式
spring AOP切入点execution表达式
|
4月前
|
XML Java 数据格式
演示spring AOP的切入表达式重用和优先级问题以及怎么实现基于xml的AOP
演示spring AOP的切入表达式重用和优先级问题以及怎么实现基于xml的AOP
35 0
|
4月前
|
XML Java 数据格式
spring通过文件属性注入bean和基于xml的bean的自动装配以及spring-eel表达式的使用加代码合集
spring通过文件属性注入bean和基于xml的bean的自动装配以及spring-eel表达式的使用加代码合集
48 0
|
4月前
|
Java Spring
spel获取spring bean
spel获取spring bean
38 0
|
5月前
|
Java Spring
Spring中的表达式语言SpEL详解
Spring中的表达式语言SpEL详解
61 0
|
6月前
|
Java API Spring
Spring判断方法名是符合给定的SPEL+表达式的+API
Spring判断方法名是符合给定的SPEL+表达式的+API
53 0