开发者

Grails PagedResultList

开发者 https://www.devze.com 2023-03-24 03:31 出处:网络
Is there any way to get a PagedResultList in grails without using criteria?I would like to avoid criteria as they are slight开发者_运维问答ly more complex and make unit testing rather annoying.Code Be

Is there any way to get a PagedResultList in grails without using criteria? I would like to avoid criteria as they are slight开发者_运维问答ly more complex and make unit testing rather annoying. Code Below

def pagedResultList = MyDomainClass.createCriteria().list(max:10, offset:0) 
                                                    { order("id", "asc") }

//Below does not return pagedResultList
def aList = MyDomainClass.list(sort:"id", order:"asc", max:10, offset: 0)


PagedResultList is just used to wrap the results of Criteria-based queries (you can see its use in the source here). If you really want to use it, you could always just invoke the constructor directly, since it will handle any list. Of course the totalCount property (which is probably what you are interested in) will then be unset.

If the idea is to get both the paged results list and the total number of results, I'm not aware of any magic that can get both in one query (even the use of PagedResultList in the source linked above issues two queries).


This seems to break in Grails 2.x because there is no costructor that just takes a list. Compare http://grails.org/doc/2.1.0/api/grails/orm/PagedResultList.html and http://docs.huihoo.com/grails/1.3.7/api/grails/orm/PagedResultList.html

0

精彩评论

暂无评论...
验证码 换一张
取 消