告别if else!试试这款轻量级流程引擎吧,跟SpringBoot绝配! (qq.com)
println("Hello Aviator Script!"); a=b+c; println("a="+a);
执行:
package com.yuyi.advanced.pis; import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.Expression; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.core.io.ClassPathResource; import org.springframework.test.context.junit.jupiter.SpringExtension; import java.io.IOException; import java.util.HashMap; @ExtendWith(SpringExtension.class) class StarterApplicationTests { @Test void contextLoads() throws IOException { // 获取路径 ClassPathResource classPathResource = new ClassPathResource("/script/hello.av"); String scriptPath = classPathResource.getPath(); // 编译 Expression exp = AviatorEvaluator.getInstance().compileScript(scriptPath); // 上下问参数 HashMap<String, Object> map = new HashMap<>(); map.put("b",3000); map.put("c",3000); // 执行 exp.execute(map); } @Test void compile(){ // 定义脚本 String script = "println(\"Hello Aviator Script\")"; // 编译 Expression exp = AviatorEvaluator.getInstance().compile(script); // 执行 exp.execute(); } }
执行结果:
标签:map,Script,exp,org,import,Aviator,轻量级 From: https://www.cnblogs.com/gzhich2019/p/17621255.html