maven引用
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-jexl</artifactId>
<version>2.1.1</version>
</dependency>
主要代码
// 引用
import org.apache.commons.jexl2.Expression;
import org.apache.commons.jexl2.JexlContext;
import org.apache.commons.jexl2.JexlEngine;
import org.apache.commons.jexl2.MapContext;
// 计算公式
String formula = "if (wfStatus > 0) { return 2 } else { return 1 }";
// 参数
JexlContext ctxt = new MapContext();
ctxt.set("wfStatus", 1);
// 调用计算引擎
JexlEngine engine = new JexlEngine();
Expression expr = engine.createExpression(formula);
// 获取返回值
Object result = expr.evaluate(ctxt);
