Spring Expression Language是否支持IN运算符?与SQL IN子句类似.
public class Security {
private secTyp1;
public Security (String aSecTyp1) {
secTyp1 = aSecTyp1;
}
}
Run Code Online (Sandbox Code Playgroud)
Security security = new Security("BOND");
StandardEvaluationContext context = new StandardEvaluationContext(security);
ExpressionParser parser = new SpelExpressionParser();
// This should return true
boolean result = parser.parseExpression("secTyp1 **IN** {'BOND','SWPI'}").getValue(context, Boolean.class);
// This should return false
result = parser.parseExpression("secTyp1 **IN** {'FUT','SWPI'}").getValue(context, Boolean.class);
Run Code Online (Sandbox Code Playgroud)
我得到以下异常
org.springframework.expression.spel.SpelParseException: EL1041E:(pos 8): After parsing a valid expression, there is still more data in the expression: 'IN'
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:118)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:56) …Run Code Online (Sandbox Code Playgroud) spring-el ×1