Grails分页用法

Grails分页用法,grails,controller,paginate,Grails,Controller,Paginate,这段代码有什么问题,因为我得到了返回到视图的所有结果,这需要我加载太多。我希望它只返回每页5 控制器: { def channel2 = Channel2.list(params) //def prog = Programmation.list() def prog def progs = [:] def temp channel2.each{ Programmation p = Programmation.withCriteri

这段代码有什么问题,因为我得到了返回到视图的所有结果,这需要我加载太多。我希望它只返回每页5

控制器:

{

    def channel2 = Channel2.list(params)
    //def prog = Programmation.list()
    def prog
    def progs = [:]
    def temp

    channel2.each{
       Programmation p = Programmation.withCriteria {
          eq('prog_channel', it)
          'between'('prog_start', new Date(), new Date() +1)    
        }
        progs.put(it.id, p)
    }

    [channel: channel2, program: progs]

}
普惠制



我想不出来。我遵循Grails helpPage,它应该可以工作。

解决方案:第一次调用该操作时,它会加载所有通道,因为params.max设置为null。要解决此问题,只需使用:

def offset

        if(!params.offset){
            offset = 0
        }

        def channel2 = Channel2.list(max:5, offset: offset)

有什么帮助吗?仍然不起作用
def offset

        if(!params.offset){
            offset = 0
        }

        def channel2 = Channel2.list(max:5, offset: offset)