在grass GSP中,我正在做类似的事情

 <g:each in="${testInstance?.testConfigs?}" var="t">

两课是
class Test{
    static hasMany = [testConfigs:TestConfig]
}

class TestConfig {
    Date dateCreated
    Date lastUpdated
    Test test
    static constraints = {
        dateCreated display:false
        lastUpdated display:false
        questionType inList:["Fill in the blanks","Multipl choice","True False"]
    }
}

如何更改每个循环的,以便按dateCreated字段降序检索testConfigs对象?

最佳答案

定义排序顺序like it says in the docs不起作用吗?

class Test{
    static hasMany = [testConfigs:TestConfig]

    static mapping = {
        testConfigs sort: 'dateCreated', order: 'desc'
    }
}

09-20 03:29