Spring spel operators example

Spring SpEL Operators:

SpEL supports the mathematical operators (+, -, /, *,

Spring SpEL Operators Example:

OperatorTest.java

import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
 
/**
 * Spring SPEL Operator test example.
 * @author w3schools
 */
public class OperatorTest {
 public static void main(String args[]){
  //Create a parser with default settings.
  ExpressionParser parser = new SpelExpressionParser(); 
 
  //Arithmetic operator expressions. 
  System.out.println(parser.parseExpression("10 * 20").getValue());  
  System.out.println(parser.parseExpression("" +
	"'Today is: '+ new java.util.Date()").getValue()); 
 
  //Relational operator expressions. 
  System.out.println(parser.parseExpression("10==5").getValue());  
 
  //Logical operator expressions.  
  System.out.println(parser.parseExpression(
                             "(10 > 5) and (5>3)").getValue()); 	  
 
 }
}

Output:

200
Today is: Mon Apr 25 16:00:45 IST 2016
false
true

 
Download this example.