解析公式Aviator简单使用

918 阅读1分钟

pom引入:

<dependency>
    <groupId>com.googlecode.aviator</groupId>
    <artifactId>aviator</artifactId>
    <version>5.2.4</version>
</dependency>

简单测试:

 public static void main(String[] args) {
        String fun = "(a+b)/3";
        Map map = new HashMap<>();
        map.put("a",11);
        map.put("b",22);
        Object execute = AviatorEvaluator.execute(fun, map);
        System.out.println(execute);
    }

执行方式 执行表达式的方法有两个:execute()、exec(); execute(),需要传递Map格式参数 exec(),不需要传递Map

官方详细文档: code.google.com/archive/p/a…