例一:使用符号
//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
分享到:
相关推荐
SpringBoot 自定义注解,属性支持SPEL表达式。介绍了SPEL表达式的解析
Spring 3.0中,新的表达式语言名叫Spring Expression Language(SpEL,直译就是Spring表达式语言)。Shaun将其描述为“嵌入在Spring编程模型上的,可以用来在Spring项目之间描述任务以及配置的微型脚本语言。SpEL...
◆Spring表达式(SpEL):用于bean定义的核心表达式分析器 ◆对基于注释的组件的更多支持:允许通过元注释创建注释的“快捷方式” ◆标准化的依赖性注入注释:对Java中依赖性注入的JSR-330标准的完整支持 ◆基于...
Spring 3.0中,新的表达式语言名叫Spring Expression Language(SpEL,直译就是Spring表达式语言)。Shaun将其描述为“嵌入在Spring编程模型上的,可以用来在Spring项目之间描述任务以及配置的微型脚本语言。SpEL...
spring spEL 表达式详解 运行环境:eclipse 构建工具:maven 不提供maven构建,maven用来解决jar包的依赖
Spring_SpEl表达式使用用例 只是一个简单的demo,有需要的可以看看
CVE-2022-22947 SpringCloud GateWay SpEL RCE.doc
SSH笔记-Spring表达式语言:SpEL,关于SpEl的字面量、引用 Bean、属性和方法、支持的运算符号
提供并简化对Druid,HikariCp,BeeCp,Dbcp2的快速集成。 提供对Mybatis-Plus,Quartz,ShardingJdbc,P6sy,Jndi等组件的集成方案。 提供 自定义数据源来源 方案(如全从数据库加载)。 提供项目启动后 动态增加移除...
Spring Expression Language (SpEL)中文文档。基于Spring4.x。
提供并简化对Druid,HikariCp,BeeCp,Dbcp2的快速集成。 提供对Mybatis-Plus,Quartz,ShardingJdbc,P6sy,Jndi等组件的集成方案。 提供 自定义数据源来源 方案(如全从数据库加载)。 提供项目启动后 动态增加移除...
主要介绍了Spring spel表达式使用方法示例,通过一些实例向大家展示了spel表达式的用法,需要的朋友可以了解下。
Spring框架中的spring-messaging模块提供了一种基于WebSocket的STOMP协议实现,STOMP消息代理在处理客户端消息时存在SpEL表达式注入漏洞,因此攻击者可以通过构造恶意的消息来实现远程代码执行。 Windows平台...
今天小编就为大家分享一篇关于Spring组件开发模式支持SPEL表达式,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
用于Spring Cloud Function SPEL表达式注入漏洞测试环境搭建,是编译好的服务端程序,命令号java -jar *.jar运行即可,服务端运行在127.0.0.1:8080端口
Spring Cloud Gateway Actuator API SpEL表达式注入命令执行 0day 漏洞复现
You can download the examples (consisting of 60 sample projects) described in this book from the following Google Code project: code.google.com/p/getting-started-with-spring-framework-2edition/ ...
spring-framework.zip,spring表达式语言(spel)spring框架
主要介绍了spring表达式语言SpEL用法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下