Spring4.x(14)---SpringEL-运算符

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;
	 
	    @Override
	    public 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



	
	

	
		
		
		
		
		
		

		
		
		

		
		
		
		
		
		
		
	


三、编写测试类

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 {

	@Test
	public 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

你可能感兴趣的:(系统架构)