`
txidol
  • 浏览: 52319 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Spring笔记 - Spring Expression Language (SpEL表达式)

 
阅读更多

基本表达式

数字5 <property name="count" value="#{5}"/>

联合方式 <property name="message" value="The value is #{5}"/>

浮点型 <property name="frequency" value="#{89.7}"/>

科学表达式10000.0 <property name="capacity" value="#{1e4}"/>

String <property name="name" value="#{'Chuck'}"/> <property name='name' value='#{"Chuck"}'/>

Boolean <property name="enabled" value="#{false}"/>

引用Bean <property name="instrument" value="#{saxophone}"/> 等价 <property name="instrument" ref="saxophone"/>

引用Bean属性 <property name="song" value="#{kenny.song}"/>

引用Bean方法 <property name="song" value="#{songSelector.selectSong()}"/>

进阶一 <property name="song" value="#{songSelector.selectSong().toUpperCase()}"/>

进阶二 防空指针 <property name="song" value="#{songSelector.selectSong()?.toUpperCase()}"/> 防空指针

使用静态类 T(java.lang.Math)

使用静态属性 <property name="multiplier" value="#{T(java.lang.Math).PI}"/>

使用静态方法 <property name="randomNumber" value="#{T(java.lang.Math).random()}"/>

运算表达式

+<property name="adjustedAmount" value="#{counter.total+42}"/>

- <property name="adjustedAmount" value="#{counter.total-20}"/>

* <property name="circumference" value="#{2 *T(java.lang.Math).PI*circle.radius}"/>

/ <property name="average" value="#{counter.total/counter.count}"/>

% <property name="remainder" value="#{counter.total%counter.count}"/>

^ <property name="area" value="#{T(java.lang.Math).PI*circle.radius^2}"/>

+ overloaded <property name="fullName value="#{performer.firstName + ' ' + performer.lastName}"/>

== eq equal <property name="equal" value="#{counter.total==100}"/>

<= <propertyname="hasCapacity"value="#{counter.total le 100000}"/>

Equal== eq
Less than < lt
Less than or equals <= le
Greater than > gt
Greater than or equals >= ge

逻辑表达式

andA logical AND operation; both sides must evaluate true for the expression to be true
or A logical OR operation; either side must evaluate true for the expression to be true
not or ! A logical NOT operation; negates the target of the operation

<property name="largeCircle" value="#{shape.kind =='circle'andshape.perimeter gt 10000}"/>

<property name="outOfStock" value="#{!product.available}"/>

条件表达式 ?: <property name="instrument" value="#{songSelector.selectSong()=='JingleBells'?piano:saxophone}"/>

<propertyname="song" value="#{kenny.song !=null?kenny.song:'Greensleeves'}"/>

等价 Elvis operator <propertyname="song"value="#{kenny.song?:'Greensleeves'}"/>

正则表达式 <property name="validEmail"value= "#{admin.email matches '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.com'}"/>

集合处理

<util:listid="cities">
<bean class="com.habuma.spel.cities.City"
p:name="Chicago"p:state="IL"p:population="2853114"/>
<bean class="com.habuma.spel.cities.City"
p:name="LasCruces"p:state="NM"p:population="91865"/>
</util:list>

List <property name="chosenCity" value="#{cities[2]}"/>

进阶 <property name="chosenCity" value="#{cities[T(java.lang.Math).random()*cities.size()]}"/>

Map <property name="chosenCity" value="#{cities['Dallas']}"/>

Properties <util:properties id="settings" location="classpath:settings.properties"/>

Properties <property name="accessToken" value="#{settings['twitter.accessToken']}"/>

systemEnvironment <property name="homePath" value="#{systemEnvironment['HOME']}"/>

systemProperties <property name="homePath" value="#{systemProperties['application.home']}"/>

String s 'This is a test'[3]

.?[] 条件选择成员 <property name="bigCities" value="#{cities.?[population gt 100000]}"/>

.^[] and .$[], for 第一个和最后一个匹配成员 <property name="aBigCity" value="#{cities.^[population gt 100000]}"/>

.![] 抽取集合 List <property name="cityNames" value="#{cities.![name]}"/>

进阶 <property name="cityNames" value="#{cities.![name+' , '+state]}"/>

进阶 <property name="cityNames" value="#{cities.?[population gt 100000].![name+' ,'+state]}"/>

分享到:
评论

相关推荐

    spring-boot-annotation-spel.zip

    SpringBoot 自定义注解,属性支持SPEL表达式。介绍了SPEL表达式的解析

    SSH笔记-SpEL

    SSH笔记-Spring表达式语言:SpEL,关于SpEl的字面量、引用 Bean、属性和方法、支持的运算符号

    spring spEL 表达式详解

    spring spEL 表达式详解 运行环境:eclipse 构建工具:maven 不提供maven构建,maven用来解决jar包的依赖

    CVE-2022-22947 SpringCloud GateWay SpEL RCE.doc

    CVE-2022-22947 SpringCloud GateWay SpEL RCE.doc

    Spring_SpEl表达式使用用例

    Spring_SpEl表达式使用用例 只是一个简单的demo,有需要的可以看看

    Spring 3.0-API 参考手册

    Spring 3.0中,新的表达式语言名叫Spring Expression Language(SpEL,直译就是Spring表达式语言)。Shaun将其描述为“嵌入在Spring编程模型上的,可以用来在Spring项目之间描述任务以及配置的微型脚本语言。SpEL...

    Spring表达式语言中文参考手册.docx

    Spring Expression Language (SpEL)中文文档。基于Spring4.x。

    spring-framework-reference 3.0

    Spring 3.0中,新的表达式语言名叫Spring Expression Language(SpEL,直译就是Spring表达式语言)。Shaun将其描述为“嵌入在Spring编程模型上的,可以用来在Spring项目之间描述任务以及配置的微型脚本语言。SpEL...

    spring-expression.zip

    Spring Expression Language(简称 SpEL)是一个支持查询和操作运行时对象导航图功能的强大的表达式语言,它的语法类似于传统 EL(如jsp中的EL表达式),但提供额外的功能,最出色的就是函数调用和简单字符串的模板...

    dynamic-datasource-spring-boot-starter-v3.5.1.zip

    Dynamic-Datasource (opens new window)- 基于 SpringBoot 的多数据源组件,功能强悍,支持 Seata ...提供使用 spel动态参数 解析数据源方案。内置spel,session,header,支持自定义。 支持 多层数据源嵌套切换 。

    spring-framework-5.0.5.RELEASE 漏洞修复

    Spring框架中的spring-messaging模块提供了一种基于WebSocket的STOMP协议实现,STOMP消息代理在处理客户端消息时存在SpEL表达式注入漏洞,因此攻击者可以通过构造恶意的消息来实现远程代码执行。 Windows平台...

    spring-jms-3.2.4.RELEASE.zip

    spring-framework.zip,spring表达式语言(spel)spring框架

    dynamic-datasource-spring-boot-starter-v3.5.1.tar.gz

    Dynamic-Datasource (opens new window)- 基于 SpringBoot 的多数据源组件,功能强悍,支持 Seata ...提供使用 spel动态参数 解析数据源方案。内置spel,session,header,支持自定义。 支持 多层数据源嵌套切换 。

    xbean-spring-3.15.zip

    spring-framework.zip,spring表达式语言(spel)spring框架

    spring-boot-reference.pdf

    SpEL Expression Conditions 46.4. Testing your Auto-configuration 46.4.1. Simulating a Web Context 46.4.2. Overriding the Classpath 46.5. Creating Your Own Starter 46.5.1. Naming 46.5.2. autoconfigure...

    Spring组件开发模式支持SPEL表达式

    今天小编就为大家分享一篇关于Spring组件开发模式支持SPEL表达式,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧

    Spring实战之Bean定义中的SpEL表达式语言支持操作示例

    主要介绍了Spring实战之Bean定义中的SpEL表达式语言支持操作,结合实例形式分析了Bean定义中的SpEL表达式语言操作步骤与实现技巧,需要的朋友可以参考下

    Spring Cloud Gateway Actuator API SpEL表达式注入命令执行 0day 漏洞复现

    Spring Cloud Gateway Actuator API SpEL表达式注入命令执行 0day 漏洞复现

    spring-boot-Thymeleaf 模板

    它与Spring框架紧密集成,并提供了对Spring Expression Language(SpEL)的支持。Spring Boot Thymeleaf提供了一个便捷的方式来在Spring Boot应用程序中使用Thymeleaf模板引擎,简化了开发过程,并提供了丰富的功能...

Global site tag (gtag.js) - Google Analytics