Grails 我面临createCriteria中的投影问题

Grails 我面临createCriteria中的投影问题,grails,groovy,createcriteria,Grails,Groovy,Createcriteria,我面临一个问题,无法从这次关闭中获得所需的结果 def authors{ results = Message.createCriteria().list { projections { author{ groupProperty('id', 'authorId') // 2nd param is alias property('username', 'username')

我面临一个问题,无法从这次关闭中获得所需的结果

def authors{
    results = Message.createCriteria().list {
        projections {
            author{
                groupProperty('id', 'authorId') // 2nd param is alias
                property('username', 'username')
            }
        }

        and{
            ...
            ...
        }
    }

    [authors:results]
}
我想在我的gsp页面上显示此列表 并希望使用别名访问这些值 (当上述条件返回数组列表时)

您可以尝试此方法

def authors{
    results = Message.createCriteria().list {
        projections {
            author{
                groupProperty('id') 
                property('username')
            }
        }

        and{
            ...
            ...
        }
    }
    List authors = results.collect{record -> [authorId : record[0], username:record[1]}
    [authors:authors]   }
你可以试试这个

def authors{
    results = Message.createCriteria().list {
        projections {
            author{
                groupProperty('id') 
                property('username')
            }
        }

        and{
            ...
            ...
        }
    }
    List authors = results.collect{record -> [authorId : record[0], username:record[1]}
    [authors:authors]   }
使用resultTransformer(标准规范。别名到实体映射)

所有投影都必须有别名。否则,生成的映射将包含空值。

使用resultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_映射)


所有投影都必须有别名。否则,生成的映射将包含空值。

提示所有投影必须有别名。我很想知道为什么我会得到空值,因为所有的投影都必须有一个别名。我很想知道为什么我会得到空值。