首页  

aviator实例     所属分类 aviator 浏览量 731
Aviator  轻量级的 java 表达式求值引擎,主要用于各种表达式的动态求值
aviator 5.3.1

com.googlecode.aviator:aviator


https://github.com/killme2008/aviatorscript

http://fnil.net/aviator/

https://www.yuque.com/boyan-avfmj/aviatorscript




import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.Expression;

import java.util.HashMap;
import java.util.Map;

public class Demo1 {
	public static void main(String[] args) throws Exception{		
		System.out.println("hello,aviator");
		String expression = "score > 90 ? \"优\" : score > 80 ? \"良\" : score > 60 ? \"及格\" : \"不及格\"";
		// 字符串可以用单引号
		expression = "score > 90 ? '优' : score > 80 ? '良' : score > 60 ? '及格' : '不及格'";

		Map<String, Object> params = new HashMap<>();
		params.put("score", 85);
		Object result = AviatorEvaluator.execute(expression, params);
		System.out.println(result);

		params.put("score", 70);
		result = AviatorEvaluator.execute(expression, params);
		System.out.println(result);

		params.put("score", 58);
		result = AviatorEvaluator.execute(expression, params);
		System.out.println(result);

		//
		Expression compiledExp = AviatorEvaluator.getCachedExpression(expression);
		System.out.println("compiledExp.1="+compiledExp);

		compiledExp = AviatorEvaluator.compile(expression,true);
		System.out.println("compiledExp.2="+compiledExp);

		params.put("score", 98);
		result = compiledExp.execute(params);
		System.out.println(result);

		params.put("score", 77);
		result = compiledExp.execute(params);
		System.out.println(result);

		compiledExp = AviatorEvaluator.getCachedExpression(expression);
		System.out.println("compiledExp.3="+compiledExp);

		AviatorEvaluator.invalidateCache(expression);
		compiledExp = AviatorEvaluator.getCachedExpression(expression);
		System.out.println("compiledExp.4="+compiledExp);
	}
}



https://gitee.com/dyyx/hellocode/blob/master/demo/aviatordemo/src/main/java/dyyx/Demo1.java

上一篇     下一篇
docker search 查看版本

docker 安装 centos7

Java简史

mac 查看 wifi 密码

Jayway JsonPath 实例

jsonpath写法