grails - 分页与集合

标签 grails pagination gorm

我有像

User{

 static hasMany=[friends:User]

}

我可以为这样的用户获得所有 friend :
user.friends

但是我需要在没有主意的情况下应用分页,有什么建议吗?

最佳答案

您可以使用条件来检索您的User对象。因此,您将能够使用分页:

int maxElementsPerPage = 15    
User.createCriteria().list(offset: currentPage * maxElementsPerPage, 
                           max: maxElementsPerPage) {
    // condition here
    'in' ('id', user.friends*.id) 
    // I'm not sure if you need to put '*.id'
} 

您只需要增加'currentPage'即可为下一页提供元素。

对于Grails标准,您应该查看official Grails criteria documentation

或者,您可以在GSP中使用Grails标记(它将处理所有内容):
<g:paginate controller="user" action="list" total="${userCount}" />

更多详细信息here

关于grails - 分页与集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37609243/

相关文章:

email - 使用模板发送电子邮件-Grails

java - 如何在 JPA 中对结果查询进行分页?

grails - 导致多对多关系

grails - 如何在Grails中动态更改Quartz CRON表达式

javascript - 我没有在React项目中定义for循环

grails - Grails GORM:常规 map

sql - GORM查询产生数据库错误(grails 1.1.1)

grails - Grails:防止具有多个关系的两个域类之间的级联关联

grails - IntelliJ Grails 3 项目 : Unable to Run Grails project

ios - 如何在tableview中显示大量数据