Spring 表达式语言检查字符串是否包含在字符串列表中

Spring Expression Language check if a string is contained in a List of Strings

我有以下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);

}

其输出始终为 false。

我错过了什么?

这是打字错误,您输入的是 CHECK_TEAM iso "CHEK_TEAM"。下面的代码会给你真实的。 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);