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 = shell.evaluate(script);
 9 System.out.println(value.toString());
10 
11 EventDetailTo to = new EventDetailTo();
12 to.setId(1);
13 to.setTitle("xxxxxx");
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());

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM