SpringEL-运算符


Spring EL 支持大多数的数学操作符、逻辑操作符、关系操作符。

1、关系操作符

  包括:等于 (==, eq),不等于 (!=, ne),小于 (<, lt),,小于等于(<= , le),大于(>, gt),大于等于 (>=, ge)

2、逻辑操作符

  包括:and,or,and not(!)

3、数学操作符

  包括:加 (+),减 (-),乘 (*),除 (/),取模 (%),幂指数 (^)。

一、编写Bean类

Number类:

package com.yiidian.domain;
/*** @author http://www.yiidian.com* */
public class Number {private int no;public int getNo() {return no;}public void setNo(int no) {this.no = no;}
}

Customer类:

package com.yiidian.domain;import java.io.Serializable;
/*** * @author http://www.yiidian.com**/
public class Customer implements Serializable{private boolean testEqual;private boolean testNotEqual;private boolean testLessThan;private boolean testLessThanOrEqual;private boolean testGreaterThan;private boolean testGreaterThanOrEqual;private boolean testAnd;private boolean testOr;private boolean testNot;private double testAdd;private String testAddString;private double testSubtraction;private double testMultiplication;private double testDivision;private double testModulus ;private 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 + "]";}public void setTestEqual(boolean testEqual) {this.testEqual = testEqual;}public void setTestNotEqual(boolean testNotEqual) {this.testNotEqual = testNotEqual;}public void setTestLessThan(boolean testLessThan) {this.testLessThan = testLessThan;}public void setTestLessThanOrEqual(boolean testLessThanOrEqual) {this.testLessThanOrEqual = testLessThanOrEqual;}public void setTestGreaterThan(boolean testGreaterThan) {this.testGreaterThan = testGreaterThan;}public void setTestGreaterThanOrEqual(boolean testGreaterThanOrEqual) {this.testGreaterThanOrEqual = testGreaterThanOrEqual;}public void setTestAnd(boolean testAnd) {this.testAnd = testAnd;}public void setTestOr(boolean testOr) {this.testOr = testOr;}public void setTestNot(boolean testNot) {this.testNot = testNot;}public void setTestAdd(double testAdd) {this.testAdd = testAdd;}public void setTestAddString(String testAddString) {this.testAddString = testAddString;}public void setTestSubtraction(double testSubtraction) {this.testSubtraction = testSubtraction;}public void setTestMultiplication(double testMultiplication) {this.testMultiplication = testMultiplication;}public void setTestDivision(double testDivision) {this.testDivision = testDivision;}public void setTestModulus(double testModulus) {this.testModulus = testModulus;}public void setTestExponentialPower(double testExponentialPower) {this.testExponentialPower = testExponentialPower;}
}

二、配置applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="numberBean" class="com.yiidian.domain.Number"></bean><bean id="customer" class="com.yiidian.domain.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></beans>

三、编写测试类

package com.yiidian.test;import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.yiidian.domain.Customer;/*** @author http://www.yiidian.com* */
public class Demo1 {@Testpublic void test1() {ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");Customer customer = (Customer)context.getBean("customer");System.out.println(customer);}}

四、运行结果

Customer [testEqual=true, testNotEqual=false, testLessThan=false, testLessThanOrEqual=true, testGreaterThan=false, testGreaterThanOrEqual=true, testAnd=false, testOr=true, testNot=true, testAdd=2.0, testAddString=1@1, testSubtraction=0.0, testMultiplication=1.0, testDivision=5.0, testModulus=0.0, testExponentialPower=4.0]

源码下载:http://pan.baidu.com/s/1pLE8a2R

Spring4.x(14)---SpringEL-运算符相关推荐

  1. C++自学14:关系运算符(bool/std::boolalpha)

    只要不是0,那么无论赋值成什么,最终都会变成1 虽然说bool类型0,是flase,非0是true,但是最终都会变成0是flase,1是true int main() { bool a = 100;s ...

  2. [编程神域 C语言浮游塔 第②期] 程序框架的搭建及14种基本运算符

    前言 都不知道有没有人在看.(悲) 经过之前的学习,我们知道了C语言的起源,C语言的基本结构以及一些基础知识. 本期我们会在此基础上向大家讲解14种运算符(主流使用).格式以及字符的输入输出.数据类型 ...

  3. c语言无视数据类型字符串存储,C语言基础-第二课-数据类型与运算符(示例代码)...

    1   C语言中的数据类型 1.1   常量 常量就是在程序中不可变化的量,常量在定义的时候必须给一个初值. 1.1.1#define 定义一个宏常量 1.1.2const 定义一个const常量 1 ...

  4. c++ primer 第14章 习题解答

    14.1节 14.1答 不同点: 重载操作符必须具有至少一个class或枚举类型的操作数. 重载操作符不保证操作数的求值顺序,例如对&&和| | 的重载版本不再具有"短路求值 ...

  5. java 新功能_Java 14的新功能

    java 新功能 2020年3月17日,Oracle发布了名为Java 14的Java新版本,其中包括许多新功能,工具,安全性,调试和更新的文档方面的改进. 但是,Oracle还向您提供Java的较旧 ...

  6. Java 14的新功能

    2020年3月17日,Oracle发布了名为Java 14的Java新版本,其中包括许多新功能,工具,安全性,调试和更新的文档方面的改进. 但是,Oracle还向您提供Java的较旧版本,因为它具有向 ...

  7. PHP相等(==双重等于)和标识(===三次等于)比较运算符有何区别?

    ==和===什么区别? 松散==比较到底如何工作? 严格===比较如何工作? 有什么有用的例子吗? #1楼 这都是关于数据类型的. 以BOOL (对或错)为例: true也等于1 , false也等于 ...

  8. c语言位运算知乎,07-C语言运算符-指趣学院

    运算符基本概念 和数学中的运算符一样, C语言中的运算符是告诉程序执行特定算术或逻辑操作的符号 例如告诉程序, 某两个数相加, 相减,相乘等 什么是表达式 表达式就是利用运算符链接在一起的有意义,有结 ...

  9. 一起来学Kotlin:概念:7. Kotlin 函数介绍:扩展函数,中缀函数,运算符函数,带有varrag输入的函数

    Kotlin:概念:7. Kotlin 函数介绍:扩展函数,中缀函数,运算符函数,带有varrag输入的函数,内联函数 这里介绍Kotlin的不同种类函数,包括:一般的函数表达方式,扩展函数,中缀函数 ...

最新文章

  1. 【最新综述】轻量级神经网络架构综述
  2. 非常好用的模糊pid温度控制算法_反应罐高低温温度控制装置
  3. 最大子段和(动态规划及分治法)
  4. little problem
  5. Exchange Server 2016管理系列课件39.新建本地移动请求
  6. python倒排索引搜索引擎_【Python】倒排索引
  7. k8s修改node的ROLES标签
  8. Struts2的标签概述
  9. CentOS7 系统升级,删除centos7开机界面多余选,升级至最新的内核
  10. android adb 进程端口号被占解决方法
  11. delphi 异步 调用 带参数_Dubbo 关于同步/异步调用的几种方式
  12. 使用 JavaScript File API 实现文件上传
  13. Java自学如何找工作?
  14. java天猫精灵_教你玩转天猫精灵:把设备接入天猫精灵
  15. Dubbo笔记 ⑭ :Dubbo集群组件 之 Directory
  16. 自动化改造要想取得最大效益,要搞清这几个问题!
  17. 11 计算机组成原理第七章 输入/输出系统 I/O系统基本概念 外部设备
  18. g729源码分析-5-基音周期搜索(下)
  19. 美团和大众点评合并后,两家的技术大牛们该咋办?
  20. CSS非布局样式和重点内容

热门文章

  1. CButton相关函数介绍
  2. 6002.mavlink通过xml生成自定义消息
  3. STM32网络之中断
  4. 数据结构之查找的概念及简单实现
  5. cmd cd命令_常用的一些dos命令分享
  6. android 画面,Android 界面组成
  7. 远程分支显示不全 idea_IDEA中的Git操作,看完你就会了
  8. java中文本框如何表示为空值_去jsp页面中文本框有NULL值的代码
  9. HTML页面的参数化实现(仿ASP)
  10. UVa 1225 Digit Counting 题解