类定义:
Java代码
-
class Book{ static domain=[pkg:"application.",name:"book",class:"Book",chinese:"书籍"] }
动态加载代码:
-
outputPath="./output" generatingClasses=["Book"] String[] loadingPaths = [‘./input‘] engine = new GroovyScriptEngine(loadingPaths) generatingClasses.each{className-> clazz = engine.loadScriptByName(className+‘.groovy‘) instance = clazz.newInstance() instance.domain.each{ key, value -> println " "+key+":"+value } }
运行结果:
D:\g.Groovy\cgtemplates\meta>generator.groovy
pkg:application.
name:book
class:Book
chinese:书籍
时间: 2024-09-17 08:59:22