gpt4 book ai didi

grails - Grails中的withCriteria和CreateCriteria有什么区别?

转载 作者:行者123 更新时间:2023-12-03 13:56:23 26 4
gpt4 key购买 nike

它们之间有什么区别,为什么我们需要在哪里使用它们,我认为它们对我来说根本没有区别?

最佳答案

值得添加我在grails文档中遇到的createCriteria()

Because that query includes pagination parameters (max and offset), this will return a PagedResultList which has a getTotalCount() method to return the total number of matching records for pagination. Two queries are still run, but they are run for you and the results and total count are combined in the PagedResultList.



Source

这意味着您可以使用 getTotalCount()而不需要发起 call (这是为您而做的)。这非常有帮助。示例文档显示:
def c = Account.createCriteria()
def results = c.list (max: 10, offset: 10) {
like("holderFirstName", "Fred%")
and {
between("balance", 500, 1000)
eq("branch", "London")
}
order("holderLastName", "desc")
}
println "Rendering ${results.size()} Accounts of ${results.totalCount}"

使用 withCriteria()时此功能不可用。

关于grails - Grails中的withCriteria和CreateCriteria有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16729188/

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