Javatpoint Logo

91-9990449935

 0120-4256464

Operators in SPEL

We can use many operators in SpEL such as arithmetic, relational, logical etc. There are given a lot of examples of using different operators in SpEL.


Examples of using operators in SPEL

  1. import org.springframework.expression.ExpressionParser;  
  2. import org.springframework.expression.spel.standard.SpelExpressionParser;  
  3.   
  4.   
  5. public class Test {  
  6. public static void main(String[] args) {  
  7. ExpressionParser parser = new SpelExpressionParser();  
  8.   
  9. //arithmetic operator  
  10. System.out.println(parser.parseExpression("'Welcome SPEL'+'!'").getValue());  
  11. System.out.println(parser.parseExpression("10 * 10/2").getValue());  
  12. System.out.println(parser.parseExpression("'Today is: '+ new java.util.Date()").getValue());  
  13.   
  14. //logical operator  
  15. System.out.println(parser.parseExpression("true and true").getValue());  
  16.   
  17. //Relational operator  
  18. System.out.println(parser.parseExpression("'sonoo'.length()==5").getValue());  
  19. }  
  20. }