Retrieving a list of GORM persistent properties for a domain

前端 未结 3 1723
鱼传尺愫
鱼传尺愫 2020-12-08 00:47

What\'s the best/easiest way to get a list of the persistent properties associated with a given GORM domain object? I can get the list of all properties, but this list cont

3条回答
  •  自闭症患者
    2020-12-08 01:11

    Try this:

    import org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass
    ...
    def d = new DefaultGrailsDomainClass(YourDomain.class)
    d.persistentProperties
    

    Here's a link to the Grails API for GrailsDomainClass (it's a link to an older version; I couldn't find a newer one after some quick searches). It's got a getPersistentProperties() (used in the code snippet above). You can traverse the API documentation to see what other methods might be useful to you.

    If you want an example, do a grails install-templates and then look at src/templates/scaffolding/create.gsp. There's a block in there where it iterates over the persistent domain properties.

提交回复
热议问题