【问题标题】:Grails paginate usageGrails 分页使用
【发布时间】:2011-12-13 15:34:17
【问题描述】:

这段代码有什么问题,因为我将所有结果都返回到视图中,这让我加载太多。我希望它每页只返回 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]

}

普惠制

<g:render id="" template="/layouts/canais"/>

<g:paginate next="Forward" prev="Back"
        maxsteps="0" max="3" controller="teste"
        action="myProgramms_canais"  
        total="${tv_megazineplus.Channel2.count()}" />

我想不通。我关注了 Grails helpPage,它应该可以工作。

【问题讨论】:

  • 对此有什么帮助吗?还是不行

标签: grails controller pagination


【解决方案1】:

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

def offset

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

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

【讨论】:

    猜你喜欢
    • 2019-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 2021-11-09
    • 1970-01-01
    相关资源
    最近更新 更多