26 lines
614 B
Java
26 lines
614 B
Java
|
package aiyh.utils;
|
||
|
|
||
|
import aiyh.utils.tool.org.apache.commons.jexl3.*;
|
||
|
|
||
|
import java.util.Map;
|
||
|
|
||
|
/**
|
||
|
* <h1>脚本工具</h1>
|
||
|
*
|
||
|
* <p>create: 2023/3/3 23:03</p>
|
||
|
*
|
||
|
* @author youHong.ai
|
||
|
*/
|
||
|
public class ScriptUtil {
|
||
|
private static final JexlEngine jexl = new JexlBuilder().create();
|
||
|
|
||
|
public static Object invokeScript(String script, Map<String, Object> params) {
|
||
|
JexlContext jc = new MapContext();
|
||
|
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||
|
jc.set(entry.getKey(), entry.getValue());
|
||
|
}
|
||
|
JexlExpression expression = jexl.createExpression(script);
|
||
|
return expression.evaluate(jc);
|
||
|
}
|
||
|
}
|