私は自分のスキャフォールディングテンプレート、具体的にはcreate.gspファイルを作成しています。私は自分のクラスで定義されたプロパティを取得したいと思います。私はこれを行う方法について多くの投稿をオンラインで見ましたが、どれもうまくいかないようです。生成-全て使用すると、次のエラーを取得Grailsスキャフォールディングテンプレート - ドメインクラスからプロパティを取得する
<%
domainClass.properties.each {
println " ${it.type} ${it.name}"
}
%>
:
は、以下の(grails templates - scaffolding controller)を試み
また、このアプローチを試みた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
ご協力いただきありがとうございます!
可能な変数[grailsテンプレートで利用可能な変数](http://stackoverflow.com/questions/34575451/variables-available-in-grails-templates) –
あなたのクエリについては、この回答を参照してください:https:// stackoverflow。 com/a/34648837/1799527 –