我正在尝试编辑grails脚手架模板以在create.gsp和edit.gsp中创建单个字段
如果我在create.gsp中添加以下内容
<%
def d = new grails.core.GrailsDomainClass (collegeapplication.Student.class)
d.persistentProperties.each {
%>
${it}
<%
}
%>
我得到
unable to resolve class grails.core.GrailsDomainClass
因此,我无法使用Groovy way to dynamically instantiate a class from String列出的任何常用方法来加载我的任何域类。或在Get domain class field names
有任何想法吗?
我想要的最终结果不是
<f:all bean="parentsInfomormation"/>
我要generate-all命令来生成每个属性的
<f:field bean="person" property="name"/>
最佳答案
在grails 3.x中使用scaffolding
插件,就不可能实现您想要实现的目标。在生成域模板时,脚手架插件不会加载任何域类,或者可以说它不会加载grails应用程序。
脚手架插件使用create-script
生成的脚本来生成模板。
In Grails 3.x it is not possible to load a Grails application within a code generation script created by the
create-script
command.
有关更多信息,请阅读link。
因此,您有两种选择:
create-command
创建您自己的脚手架任务,如上面的链接中所述。 FormFieldsTagLib
来为<f:all bean=""/>
标记定义自定义行为。 关于grails - Grails模板中可用的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34575451/