码迷,mamicode.com
首页 > 编程语言 > 详细

Java执行groovy脚本

时间:2014-07-13 09:26:06      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:style   blog   java   color   os   div   

 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 = 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 = shell.evaluate(script);
21 System.out.println(value.toString());

 

Java执行groovy脚本,布布扣,bubuko.com

Java执行groovy脚本

标签:style   blog   java   color   os   div   

原文地址:http://www.cnblogs.com/warrior/p/3838047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!