This commit is contained in:
Looly 2022-09-23 23:59:38 +08:00
parent 1f554b7759
commit f8c3b8c109
2 changed files with 13 additions and 11 deletions

View File

@ -17,6 +17,9 @@ public class JexlEngine implements ExpressionEngine {
private final org.apache.commons.jexl3.JexlEngine engine;
/**
* 构造
*/
public JexlEngine(){
engine = (new JexlBuilder()).cache(512).strict(true).silent(false).create();
}

View File

@ -19,16 +19,15 @@ public class RhinoEngine implements ExpressionEngine {
@Override
public Object eval(final String expression, final Map<String, Object> context) {
final Context ctx = Context.enter();
final Scriptable scope = ctx.initStandardObjects();
if (MapUtil.isNotEmpty(context)) {
context.forEach((key, value)->{
// 将java对象转为js对象后放置于JS的作用域中
ScriptableObject.putProperty(scope, key, Context.javaToJS(value, scope));
});
}
final Object result = ctx.evaluateString(scope, expression, "rhino.js", 1, null);
Context.exit();
return result;
try(final Context ctx = Context.enter()){
final Scriptable scope = ctx.initStandardObjects();
if (MapUtil.isNotEmpty(context)) {
context.forEach((key, value)->{
// 将java对象转为js对象后放置于JS的作用域中
ScriptableObject.putProperty(scope, key, Context.javaToJS(value, scope));
});
}
return ctx.evaluateString(scope, expression, "rhino.js", 1, null);
} // auto close
}
}