我是MVEL的新手,我只是尝试使用下面的代码片段。但我面临以下例外。请建议。
代码段是:
public static void main(String[] args) {
Map map = new HashMap();
VariableResolverFactory functionFactory = new MapVariableResolverFactory(map);
MVEL.eval("checkNullValue = def (x) {x == null ? 0 : x};", functionFactory);
map.put("a", 10);
map.put("b", 10);
map.put("c", 20);
Serializable str = MVEL.compileExpression("d = ( ( checkNullValue(a) + checkNullValue(b) + checkNullValue(c) ) > 2 ) ? d=2 : d=3");
MVEL.executeExpression(str, map, functionFactory);
System.out.println(map);
System.out.println(map.get("d"));
}
而例外是:
Exception in thread "main" [Error: invalid number literal: 0 :]
[Near : {... = def (x) {x == null ? 0 : x} ....}]
^