gpt4 book ai didi

grails - 在 GORM findBy* 查询中,如何在限制使用 "sort"之前使用 "max"

转载 作者:行者123 更新时间:2023-12-04 15:47:18 24 4
gpt4 key购买 nike

以下 grails 查询将结果数限制为 3,然后按 id 对它们进行排序:
def results = Domain.findAllByFoo(foo, [sort: 'id', order: 'desc', max: 3])
所以这将返回 ID 1 到 3,然后颠倒它们的顺序,以便
results*.id == [3,2,1]
有没有办法先排序,后限制,这样
results*.id == [99,98,97]
我目前的解决方法是这样的:
if (results.size() > max) results = results[0..<max]

最佳答案

这是由于 bug in Grails这是在 2.0.4 中修复的。

关于grails - 在 GORM findBy* 查询中,如何在限制使用 "sort"之前使用 "max",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9275422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com