【发布时间】:2016-04-07 03:20:08
【问题描述】:
我正在尝试编辑 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"/> 每个属性
【问题讨论】:
-
你为什么不试试
def domainClass = grailsApplication.getDomainClass(collegeapplication.Student.class)? -
@VinayPrajapati 如何获取 grailsApplication 的实例?我认为在运行 generate-all 命令时无论如何它都不可用。
-
你默认在 gsp 页面上得到它。在模板上,您可以毫无问题地使用它。试试看,或者如果您需要完整的解决方案,我可以将其粘贴为答案。 :)
-
@VinayPrajapati 它说没有这样的属性 grailsApplication。已经试过了。
标签: grails groovy grails-3.0.10