如何根据属性值对对象列表进行排序

问题描述 投票:0回答:1

我正在使用CriteraBuilder返回对象列表。如果它等于状态“PENDING”,我想通过对象中的属性值对此列表(希望在查询中)进行排序。对象上的状态可以是“有效,过期或待定”。状态为“待定”的对象我想先放在返回的列表中。注意我希望能够对此列表进行分页。

准则

def getAllIds(Map opts = [:]) {
    def max = opts.max ?: 10
    def offset = opts.offset ?: 0

    def c = Identification.createCriteria()
    List<Identification> ids = c.list(max: max, offset: offset) {
        //sort here if status == "PENDING"
    }

    return ids
}
sorting grails hibernate-criteria
1个回答
0
投票

您可以使用'withCriteria'代替'createCrkteria'+'list'并在其中使用'order'

http://docs.grails.org/3.1.1/ref/Domain%20Classes/withCriteria.html

© www.soinside.com 2019 - 2024. All rights reserved.