如何在 Grails 中按多个字段排序? [英] How to order by more than one field in Grails?
本文介绍了如何在 Grails 中按多个字段排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让列表按两个字段排序,比如姓氏和名字?
Is there a way to get a list ordered by two fields, say last and first names?
我知道 .listOrderByLastAndFirst
和 .list(sort:'last, first')
不起作用.
I know .listOrderByLastAndFirst
and .list(sort:'last, first')
won't work.
推荐答案
这个旧的解决方案不再有效.请参阅下面 mattlary 的回答
您可能需要用 HQL 编写自定义查找器或使用 Criteria Builder.
You may have to write a custom finder in HQL or use the Criteria Builder.
MyDomain.find("from Domain as d order by last,first desc")
或
def c = MyDomain.createCriteria()
def results = c.list {
order("last,first", "desc")
}
这篇关于如何在 Grails 中按多个字段排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文