我有以下SPEL测试代码:
public void test(){
ExpressionParser parser = new SpelExpressionParser();
String input = "ADITYA";
List<String> coreTeam = Arrays.asList("ASHISH","ADITYA","SUMANT","SHASHIKANT","HATIM");
System.out.println(coreTeam.toString());
StandardEvaluationContext coreTeamContext = new StandardEvaluationContext(coreTeam);
coreTeamContext.setVariable("CORE_TEAM",coreTeam);
coreTeamContext.setVariable("CHEK_TEAM",input);
Expression exp40 = parser.parseExpression("#CORE_TEAM.contains(#CHECK_TEAM)");
Boolean s = exp40.getValue(coreTeamContext,Boolean.class);
}
其输出始终为假。
我想念什么?
最佳答案
这是拼写错误,您在“ CHEK_TEAM”中输入了CHECK_TEAM iso。下面的代码将使您成真。
ExpressionParser解析器= new SpelExpressionParser();
String input = "ADITYA";
List<String> coreTeam = Arrays.asList("ASHISH","ADITYA","SUMANT","SHASHIKANT","HATIM");
System.out.println(coreTeam.toString());
StandardEvaluationContext coreTeamContext = new StandardEvaluationContext(coreTeam);
coreTeamContext.setVariable("CORE_TEAM",coreTeam);
coreTeamContext.setVariable("CHEK_TEAM",input);
Expression exp40 = parser.parseExpression("#CORE_TEAM.contains(#CHEK_TEAM)");
Boolean s = exp40.getValue(coreTeamContext,Boolean.class);