sorting - 如何基于属性值对对象列表进行排序

标签 sorting grails hibernate-criteria

我正在使用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
}

最佳答案

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

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

关于sorting - 如何基于属性值对对象列表进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51792007/

相关文章:

C编程: Sorting Structures with two parameters

javascript - javascript中基于2个键值对的排序

oracle - Grails 3 - 按 CLOB 值查找对象

java - Hibernate Criteria 限制字段命名困惑

python - 如何逐行对文本文件进行排序

php - 循环以按字母顺序返回所有 Woocommerce 产品标签

grails - 如何在grails中使用左连接?

spring - 身份验证时Auth0:NoSuchMethodError

spring - 如何使用 Hibernate 配置多个模式

hibernate - Hibernate 连接表的标准