【发布时间】:2016-07-09 11:13:33
【问题描述】:
我正在处理我的脚手架模板,更具体地说是 create.gsp 文件。我想获得在我的类中定义的属性。我在网上看到很多关于如何做到这一点的帖子,但似乎没有一个有效。
尝试了以下方法 (grails templates - scaffolding controller):
<%
domainClass.properties.each {
println " ${it.type} ${it.name}"
}
%>
使用 generate-all 时出现以下错误:
Error occurred running Grails CLI: No such property: domainClass for class: groovy.lang.Binding
也试过这种方法:
<% import grails.persistence.Event %>
<%
excludedProps = Event.allEvents.toList() << 'version' << 'dateCreated' << 'lastUpdated'
persistentPropNames = domainClass.persistentProperties*.name
props = domainClass.properties.findAll { persistentPropNames.contains(it.name) && !excludedProps.contains(it.name) && (domainClass.constrainedProperties[it.name] ? domainClass.constrainedProperties[it.name].display : true) }
Collections.sort(props, comparator.constructors[0].newInstance([domainClass] as Object[]))
for (p in props) { %>
<g:message code="${domainClass.propertyName}.${prefix}${p.name}.label" default="${p.naturalName}" />
<% } %>
使用 generate-all 时出现以下错误:
Error occurred running Grails CLI: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
GStringTemplateScript4.groovy: 2: Unknown type: IMPORT at line: 2 column: 54. File: GStringTemplateScript4.groovy @ line 2, column 54.
turn { out -> out << """"""; import gra
是我遗漏了什么还是 Grails 3 的方法不同?
使用 Grails 3.0.11 版
感谢您的帮助!
【问题讨论】:
-
查看此答案以了解您的问题:stackoverflow.com/a/34648837/1799527
标签: grails grails-3.0