W3Schools Learner's Blog

W3Schools Programming knowledge summary website

div

12/23/2017

Operators in Spring Expression Language

We can use many operators in Spring Expression Language 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. }  

No comments:

Post a Comment

Note: only a member of this blog may post a comment.