mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add script support
This commit is contained in:
parent
283f7b32ab
commit
d2900600e0
@ -6,6 +6,8 @@
|
||||
# 5.7.14 (2021-09-22)
|
||||
|
||||
### 🐣新特性
|
||||
* 【extra 】 修复HttpCookie设置cookies的方法,不符合RFC6265规范问题(issue#I4B70D@Gitee)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【http 】 修复HttpCookie设置cookies的方法,不符合RFC6265规范问题(pr#418@Gitee)
|
||||
|
||||
|
@ -23,7 +23,15 @@ public class JexlEngine implements ExpressionEngine {
|
||||
|
||||
@Override
|
||||
public Object eval(String expression, Map<String, Object> context) {
|
||||
return engine.createExpression(expression).evaluate(new MapContext(context));
|
||||
final MapContext mapContext = new MapContext(context);
|
||||
|
||||
try{
|
||||
return engine.createExpression(expression).evaluate(mapContext);
|
||||
} catch (Exception ignore){
|
||||
// https://gitee.com/dromara/hutool/issues/I4B70D
|
||||
// 支持脚本
|
||||
return engine.createScript(expression).execute(mapContext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,6 +9,9 @@ import cn.hutool.extra.expression.engine.spel.SpELEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExpressionUtilTest {
|
||||
|
||||
@Test
|
||||
@ -33,6 +36,17 @@ public class ExpressionUtilTest {
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jexlScriptTest(){
|
||||
ExpressionEngine engine = new JexlEngine();
|
||||
|
||||
String exps2="if(a>0){return 100;}";
|
||||
Map<String,Object> map2=new HashMap<>();
|
||||
map2.put("a", 1);
|
||||
Object eval1 = engine.eval(exps2, map2);
|
||||
Assert.assertEquals(100, eval1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mvelTest(){
|
||||
ExpressionEngine engine = new MvelEngine();
|
||||
|
Loading…
x
Reference in New Issue
Block a user