首页 > 代码库 > Java执行groovy脚本
Java执行groovy脚本
1 Binding binding = new Binding(); 2 binding.setVariable("foo", new Integer(2)); 3 GroovyShell shell = new GroovyShell(binding); 4 5 String script = "import com.myb.to.infrastructure.Md5Util; " 6 + "def a = 12; println ‘C# md5:‘ + Md5Util.md5(‘C#‘); " 7 + "return foo * a "; 8 Object value =http://www.mamicode.com/ shell.evaluate(script); 9 System.out.println(value.toString());10 11 EventDetailTo to = new EventDetailTo();12 to.setId(1);13 to.setTitle("狗B是怎么炼成的");14 binding = new Binding();15 binding.setVariable("to", to);16 shell = new GroovyShell(binding);17 script = "import com.myb.to.EventDetailTo; "18 + "def getTitle(EventDetailTo to) { return to.getTitle()}; "19 + "getTitle(to)";20 value =http://www.mamicode.com/ shell.evaluate(script);21 System.out.println(value.toString());
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。