package com.bfrj.core.groovy; import java.util.HashMap; import java.util.Map; import org.jeecgframework.core.util.ApplicationContextUtil; import org.springframework.context.ApplicationContext; /** * 公式计算 * */ public class GroovyParse { /** * 公式解析计算 */ public static Object formulaParse(String formula, Map<String, Object> map) { ApplicationContext context = ApplicationContextUtil.getContext(); GroovyScriptEngine groovyScriptEngine = context.getBean(GroovyScriptEngine.class); Object value = groovyScriptEngine.executeObject(formula, map); return value; } public static void main(String[] args) { String formula = "return (a * b);"; Map map = new HashMap(); map.put("a", 900); map.put("b", 10); GroovyScriptEngine groovyScriptEngine = new GroovyScriptEngine(); Object value = groovyScriptEngine.executeObject(formula, map); System.out.println(value); } }
版权声明:本文博主原创文章,博客,未经同意不得转载。
时间: 2024-10-27 06:37:17