我们可以在SpEL中使用许多运算符,例如算术,关系,逻辑等。给出了很多在SpEL中使用不同运算符的示例。
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class Test {
public static void main(String[] args) {
ExpressionParser parser = new SpelExpressionParser();
//算术运算符
System.out.println(parser.parseExpression("'Welcome SPEL'+'!'").getValue());
System.out.println(parser.parseExpression("10 * 10/2").getValue());
System.out.println(parser.parseExpression("'Today is: '+ new java.util.Date()").getValue());
//逻辑运算符
System.out.println(parser.parseExpression("true and true").getValue());
//关系运算符
System.out.println(parser.parseExpression("'sonoo'.length()==5").getValue());
}
}