下面列出了怎么用org.springframework.expression.common.TemplateAwareExpressionParser的API类实例代码及写法,或者点击链接到github查看源代码。
public static void parseTemplateAwareExpression(String property) {
TemplateAwareExpressionParser parser = new SpelExpressionParser();
//Static value not that useful .. but safe
Expression exp1 = parser.parseExpression("'safe expression'");
String constantValue = exp1.getValue(String.class);
System.out.println("exp1="+constantValue);
StandardEvaluationContext testContext = new StandardEvaluationContext(TEST_PERSON);
//Unsafe if the input is control by the user..
Expression exp2 = parser.parseExpression(property+" == 'Benoit'");
String dynamicValue = exp2.getValue(testContext, String.class);
System.out.println("exp2="+dynamicValue);
}