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