1

この閉鎖から必要な結果を得るのに問題に直面しています

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

        and{
            ...
            ...
        }
    }

    [authors:results]
}

このリストをgspページに表示し、エイリアスを使用して値にアクセスしたい(上記の基準が配列のリストを返している間)

4

2 に答える 2

6

resultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP)を使用します。

import org.hibernate.criterion.CriteriaSpecification
Message.createCriteria().list {
    resultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP)
    projections {
        author{
            groupProperty('id', 'authorId')
            property('username', 'username')
        }
    }
}

すべてのプロジェクションにはエイリアスが必要です。それ以外の場合、結果のマップにはnullが含まれます。

于 2013-05-07T01:07:01.977 に答える
3

あなたはこれを試すことができます

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]   }
于 2011-08-17T05:44:56.570 に答える