mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add script support
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
# 5.7.14 (2021-09-22)
|
# 5.7.14 (2021-09-22)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
|
* 【extra 】 修复HttpCookie设置cookies的方法,不符合RFC6265规范问题(issue#I4B70D@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【http 】 修复HttpCookie设置cookies的方法,不符合RFC6265规范问题(pr#418@Gitee)
|
* 【http 】 修复HttpCookie设置cookies的方法,不符合RFC6265规范问题(pr#418@Gitee)
|
||||||
|
|
||||||
|
@@ -23,7 +23,15 @@ public class JexlEngine implements ExpressionEngine {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object eval(String expression, Map<String, Object> context) {
|
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.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class ExpressionUtilTest {
|
public class ExpressionUtilTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -33,6 +36,17 @@ public class ExpressionUtilTest {
|
|||||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
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
|
@Test
|
||||||
public void mvelTest(){
|
public void mvelTest(){
|
||||||
ExpressionEngine engine = new MvelEngine();
|
ExpressionEngine engine = new MvelEngine();
|
||||||
|
Reference in New Issue
Block a user