(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
ExpressionParser parser = new SpelExpressionParser();(2)
StandardEvaluationContext context = new StandardEvaluationContext();
// evals to "Hello World"(3)
String helloWorld = (String) parser.parseExpression("'Hello World'").getValue();(4)
double avogadrosNumber = (Double) parser.parseExpression("6.0221415E+23").getValue();(5)
int maxValue = (Integer) parser.parseExpression("0x7FFFFFFF").getValue();(6)
boolean trueValue = (Boolean) parser.parseExpression("true").getValue();(7)
Object nullValue = parser.parseExpression("null").getValue();(8)
int year = (Integer) parser.parseExpression("Birthdate.Year + 1900").getValue(context);(9)
boolean trueValue = parser.parseExpression("2 == 2").getValue(Boolean.class);(10)
boolean trueValue = parser.parseExpression("'black' < 'block'").getValue(Boolean.class);(11)
boolean falseValue = parser.parseExpression("'xyz' instanceof T(int)").getValue(Boolean.class);(12)
boolean trueValue = parser.parseExpression("'5.00' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
本文深入探讨了SpEL表达式在Java中的应用,通过实例展示了如何使用SpEL表达式进行字符串、数字、布尔值及null值的转换,并介绍了其在不同场景中的用法。
3万+

被折叠的 条评论
为什么被折叠?



