我們可以在SpEL中使用許多運算符,例如算術(shù),關(guān)系,邏輯等。給出了很多在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(); //算術(shù)運算符 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()); //關(guān)系運算符 System.out.println(parser.parseExpression("'sonoo'.length()==5").getValue()); } }