引入依赖
<dependency> <groupId>com.googlecode.aviator</groupId> <artifactId>aviator</artifactId> <version>5.2.6</version> </dependency>
使用
//计算数字
System.out.println(AviatorEvaluator.execute("1+2*3"));
//字符型计算
String expression="'hello '+ name";
Map<String ,Object> m1=new HashMap<>();
m1.put("name","tony");
System.out.println(AviatorEvaluator.execute(expression,m1));
//判断行计算
String exp2="a+b>c";
Map<String,Object> m2=new HashMap<>();
m2.put("a",5);
m2.put("b",6);
m2.put("c",7);
System.out.println(AviatorEvaluator.execute(exp2,m2));