a
, b
정수이고 애완 동물이 유형 이라고 가정 합니다.HashMap<String, Integer>
아래 식을 미리 컴파일 할 때 pets.containsKey(\"Dogs\")
노드는 CompiledExpression 개체 내에서 null입니다.
CompiledExpression compiledExpression = new ExpressionCompiler("a > 0 && b > 0 && pets.containsKey(\"Dogs\")").compile();
return (boolean) MVEL.executeExpression(compiledExpression, params);
그러나 내가 뭔가를 할 때
boolean res = (boolean) MVEL.eval("a > 0 && b > 0 && pets.containsKey(\"Dogs\")", params);
잘 작동하고 적절한 응답을받습니다.
해시 맵과 같은 객체를 포함하는 표현식을 미리 컴파일하는 방법이 있습니까?
두 작업 모두 동일한 방식으로 구현했습니다.
Map<String, String> pets = new HashMap<>();
pets.put("dog", "DOG");
pets.put("cat", "CAT");
Integer a = 10;
Integer b = 20;
Map<String, Object> params = new HashMap<>();
params.put("$a", a);
params.put("$b", b);
params.put("$map", pets);
params.put("$key", "dog");
CompiledExpression expression = new ExpressionCompiler("$a > 0 && $b > 0 && $map.containsKey($key)").compile();
System.out.println(MVEL.executeExpression(expression, params));
System.out.println(MVEL.eval("$a > 0 && $b > 0 && $map.containsKey($key)", params));
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다