看一下 create-script 命令。
创建脚本快速参考...
创建脚本用户指南
这将允许您创建自己的脚本来进行代码生成,但我认为它不允许您访问 Grails 3.(1) 中的 GORM 域属性。我实际上在这里发布了我自己的问题:如何在 GroovyScriptCommand 中访问 GORM 对象属性?
我首先运行 install-templates 命令,然后运行 create-script 命令,不确定是否需要,但它给了我一些有限的示例模板可供查看。
这是我创建的示例。我将 println 语句放入其中,以便我可以看到模型上我必须使用的不同属性。它们感觉有点受限,因为它们都基于您输入的命令行参数,而不是实际 Grails 工件的实例。
src/main/scripts/geta-create-screen-groovy:
import grails.build.logging.ConsoleLogger
description("Creates a GETA scaffolded controller, views, and integration test artifacts") {
usage 'geta-create-screen [domain name]'
completer org.grails.cli.interactive.completers.DomainClassCompleter
argument name:'Controller Name', description:"The name of controller", required:true
flag name:'force', description:"Whether to overwrite existing files"
}
def model = model(args[0])
def overwrite = flag('force') ? true : false
println "DAC: model.className:..... ${model.className}"
println "DAC: model.fullName:...... ${model.fullName}"
println "DAC: model.propertyName:.. ${model.propertyName}"
println "DAC: model.packageName:... ${model.packageName}"
println "DAC: model.simpleName:.... ${model.simpleName}"
println "DAC: model.lowerCaseName:. ${model.lowerCaseName}"
println "DAC: model.packagePath:... ${model.packagePath}"
render template: template('scaffolding/EtaController.groovy'),
destination: file("grails-app/controllers/${model.packagePath}/${model.convention("Controller")}.groovy"),
model: model,
overwrite: overwrite
render template: template('scaffolding/EtaDomainObject.groovy'),
destination: file("grails-app/domain/${model.packagePath}/${model.convention("Domain")}.groovy"),
model: model,
overwrite: overwrite
render template: template('scaffolding/EtaService.groovy'),
destination: file("grails-app/services/${model.packagePath}/${model.convention("Service")}.groovy"),
model: model,
overwrite: overwrite
render template: template('scaffolding/EtaGsp.gsp'),
destination: file("grails-app/views/${model.packagePath}/${model.propertyName}/${model.propertyName}.gsp"),
model: model,
overwrite: overwrite
render template: template('scaffolding/EtaGspTabHeader.gsp'),
destination: file("grails-app/views/${model.packagePath}/${model.propertyName}/_tabHeader.gsp"),
model: model,
overwrite: overwrite
return true
模板:src/main/templates/scaffolding/EtaController.groovy
<%=packageName ? "package ${packageName}" : ''%>
class ${className}Controller {
static scaffold = ${className}
def index (){
render view: "${packageName.replaceAll('\\\\', '/')}/${propertyName}/${propertyName}.gsp"
}
}
执行命令: grails geta-create-screen my.package.MyClass --force --stacktrace --verbose