Spring EL运算符实例
- 关系运算符 – 等于 (==, eq), 不等于 (!=, ne), 小于 (<, lt), 小于或等于 (<= , le), 大于 (>, gt), 和大于或等于 (>=, ge).
- 逻辑运算符 – 且, 或, 非 (!).
- 数学运算符 – 加法(+), 减法 (-), 乘法 (*), 除法(/), 除模(%) 和指数幂 (^).
Spring EL以注解的形式
package com.yiibai.core;import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component("customerBean")
public class Customer {//Relational operators@Value("#{1 == 1}") //trueprivate boolean testEqual;@Value("#{1 != 1}") //falseprivate boolean testNotEqual;@Value("#{1 < 1}") //falseprivate boolean testLessThan;@Value("#{1 <= 1}") //trueprivate boolean testLessThanOrEqual;@Value("#{1 > 1}") //falseprivate boolean testGreaterThan;@Value("#{1 >= 1}") //trueprivate boolean testGreaterThanOrEqual;//Logical operators , numberBean.no == 999@Value("#{numberBean.no == 999 and numberBean.no < 900}") //falseprivate boolean testAnd;@Value("#{numberBean.no == 999 or numberBean.no < 900}") //trueprivate boolean testOr;@Value("#{!(numberBean.no == 999)}") //falseprivate boolean testNot;//Mathematical operators@Value("#{1 + 1}") //2.0private double testAdd;@Value("#{'1' + '@' + '1'}") //1@1private String testAddString;@Value("#{1 - 1}") //0.0private double testSubtraction;@Value("#{1 * 1}") //1.0private double testMultiplication;@Value("#{10 / 2}") //5.0private double testDivision;@Value("#{10 % 10}") //0.0private double testModulus ;@Value("#{2 ^ 2}") //4.0private double testExponentialPower;@Overridepublic String toString() {return "Customer [testEqual=" + testEqual + ", testNotEqual="+ testNotEqual + ", testLessThan=" + testLessThan+ ", testLessThanOrEqual=" + testLessThanOrEqual+ ", testGreaterThan=" + testGreaterThan+ ", testGreaterThanOrEqual=" + testGreaterThanOrEqual+ ", testAnd=" + testAnd + ", testOr=" + testOr + ", testNot="+ testNot + ", testAdd=" + testAdd + ", testAddString="+ testAddString + ", testSubtraction=" + testSubtraction+ ", testMultiplication=" + testMultiplication+ ", testDivision=" + testDivision + ", testModulus="+ testModulus + ", testExponentialPower="+ testExponentialPower + "]";}}
package com.yiibai.core;import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component("numberBean")
public class Number {@Value("999")private int no;public int getNo() {return no;}public void setNo(int no) {this.no = no;}}
执行
Customer obj = (Customer) context.getBean("customerBean");
System.out.println(obj);
输出结果
Customer [testEqual=true, testNotEqual=false, testLessThan=false, testLessThanOrEqual=true, testGreaterThan=false, testGreaterThanOrEqual=true, testAnd=false, testOr=true, testNot=false, testAdd=2.0, testAddString=1@1, testSubtraction=0.0, testMultiplication=1.0, testDivision=5.0, testModulus=0.0, testExponentialPower=4.0]
Spring EL以XML形式
请参阅在XML文件定义bean的等效版本。在XML中,类似 < 小于符号不支持,应该使用下面所示文本形式,例如文本等值, ('<' = 'lt') 和 ('<=' = 'le').
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><bean id="customerBean" class="com.yiibai.core.Customer"><property name="testEqual" value="#{1 == 1}" /><property name="testNotEqual" value="#{1 != 1}" /><property name="testLessThan" value="#{1 lt 1}" /><property name="testLessThanOrEqual" value="#{1 le 1}" /><property name="testGreaterThan" value="#{1 > 1}" /><property name="testGreaterThanOrEqual" value="#{1 >= 1}" /><property name="testAnd" value="#{numberBean.no == 999 and numberBean.no lt 900}" /><property name="testOr" value="#{numberBean.no == 999 or numberBean.no lt 900}" /><property name="testNot" value="#{!(numberBean.no == 999)}" /><property name="testAdd" value="#{1 + 1}" /><property name="testAddString" value="#{'1' + '@' + '1'}" /><property name="testSubtraction" value="#{1 - 1}" /><property name="testMultiplication" value="#{1 * 1}" /><property name="testDivision" value="#{10 / 2}" /><property name="testModulus" value="#{10 % 10}" /><property name="testExponentialPower" value="#{2 ^ 2}" /></bean><bean id="numberBean" class="com.yiibai.core.Number"><property name="no" value="999" /></bean></beans>
Spring EL运算符实例相关推荐
- Spring EL bean引用实例
在Spring EL,可以使用点(.)符号嵌套属性参考一个bean.例如,"bean.property_name". public class Customer {@Value(& ...
- Spring EL方法调用实例
Spring表达式语言(使用SpEL)允许开发人员使用表达式来执行方法和将返回值以注入的方式到属性,或叫作"使用SpEL方法调用". Spring EL在注解的形式 了解如何实现S ...
- Spring EL hello world实例
Spring EL与OGNL和JSF EL相似,计算评估或在bean创建时执行.此外,所有的Spring表达式都可以通过XML或注解. 在本教程中,我们将学习如何使用Spring表达式语言(SpEL) ...
- Spring EL表达式使用详解
Spring EL表达式使用详解 什么是Spring EL表达式 注入字面值 注入操作系统(OS)的属性 注入properties配置文件中数据 Bean属性调用 Bean方法调用 T运算符 构造器 ...
- Java访问静态常量_Java如何在Spring EL中访问静态方法或常量?
在这个例子中,您将学习如何使用Spring Expression Language访问类范围的方法或常量.要访问类范围的方法或常量T(),例如,您将需要使用Spring EL的运算符T(java.la ...
- Spring EL 表达式的简单介绍和使用
文章目录 1. 简单介绍 1.1. 什么是 Spring EL 1.2. 为什么要使用 Spring EL 1.3. 如何使用 Spring EL 2. 简单使用 3. EL 表达式解析引擎 3.1. ...
- Spring 在 xml配置文件 或 annotation 注解中 运用Spring EL表达式
Spring EL 一:在Spring xml 配置文件中运用 Spring EL Spring EL 采用 #{Sp Expression Language} 即 #{spring表达式} ...
- 【SpringBoot】【Thyemeleaf 】【Spring EL表达式】 SPEL调用静态类、静态方法
前言 spring 5.0.6.RELEASE Thyemeleaf 3.0 SpringBoot 2.3.4.RELEASE Spring EL表达式 调用静态类.静态方法 参考这里:https:/ ...
- spring el 三元表达式
前言 spring 5.0.6.RELEASE 三元表达式 spring el 的三元表达式提供了一个简便的写法,可以省略true的值,如下: ExpressionParser parser = ne ...
最新文章
- Normalize.css :一种用于重置默认的CSS样式的样式工具
- python服务器qt客户端_python3+PyQt5 创建多线程网络应用-TCP客户端和TCP服务器实例...
- Shiro过滤器配置(ShiroFilterFactoryBean)
- IntellijIDEA配置Tomcat
- 华为机试HJ75:公共子串计算
- python中不能使用下标运算的是_下列选项中,不能使用下标运算的是() (3.0分)_学小易找答案...
- 逻辑回归(Logistic Regression)学习笔记
- 应用程序虚拟化,序列化实验 Microsoft Desktop Optimization Pack 实现一个应用程
- 统计学习方法——第四章朴素贝叶斯及c++实现
- 学术壁报模板_中华医学会核医学分会2020年学术年会征文通知
- html中五号字体是多少像素,5号字是多大(字体尺寸对照表mm)
- 第三方支付系统技术分享
- python小欢喜(八)俄罗斯方块 (3) 组合对象的旋转
- 【cocos源码学习】解决cocos2d-x-4.0 Android Demo构建遇到的问题
- 广告拦截软件测试简历,ADSafe广告拦截效果测试
- ajax带参数get,使用jQuery ajax方法传递GET参数
- 通过CSS样式缩放图片导致图片模糊的解决方案
- Python实现SVM的实例(包括网格调参和测试)总结综述
- 最新蓝色网址/公众号导航站源码+Yzmcms内核开发
- 前端工具字典,为你开发路上披荆斩棘
热门文章
- Qt Creator制作动画
- C语言计数排序Counting sort 算法(附完整源码)
- QT的QDateTimeAxis类的使用
- 文件传输服务器多目录,node ftp 模块 如何把本地多个文件夹或者文件上传到服务器...
- python做公司内部系统错误_Python程序可能导致文件系统错误?
- python安装、anaconda安装、pycharm安装(学习笔记,自己重新整理后的内容,最新版本工具安装)
- Java程序执行Linux命令
- Struts 拦截器权限控制【通过拦截器实现登录后跳转到登录前页面】
- Oracle实例和服务知识点
- 窗口分析函数19_Mysql查询窗口函数里第一个 最后一个 第N个元素的值的案例详解(FIRST_VALUE LAST_VALUE NVH_VALUE)