grails templates - scaffolding controller

后端 未结 2 2024
遇见更好的自我
遇见更好的自我 2021-01-28 00:37

I\'m a newbie on grails. I am now currently working on my scaffolding templates especially on my controllers. I wanted a customized controller everytime I generate it so I used

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-28 01:09

    edit.gsp, show.gsp and list.gsp templates all have logic for creating fields basing on domain class, you can see there how it's done.

    Basically, when you include groovy code in your template, you can access domain class by using domainClass variable, and then you can print properties declarations by iterating over array returned by getProperties(), like this:

    <%
        domainClass.properties.each {
            println "    ${it.type} ${it.name}"
        }
    %>
    

提交回复
热议问题