Grails分页不工作

Grails分页不工作,grails,gsp,paginate,Grails,Gsp,Paginate,我已经花了一周的时间试图解决这个分页问题,但是没有得到好的结果 我的控制器里有这个 PatientController{ def show(Long id) { def patientInstance = Patient.get(id) if (!patientInstance) { flash.message = message(code: 'default.not.found.message', args: [message(code: 'pa

我已经花了一周的时间试图解决这个分页问题,但是没有得到好的结果

我的控制器里有这个

    PatientController{
    def show(Long id) {
    def patientInstance = Patient.get(id)
    if (!patientInstance) {
        flash.message = message(code: 'default.not.found.message', args: [message(code: 'patient.label', default: 'Patient'), id])
        return
    }



    def historyInstance = History.findAllByPatient(patientInstance)
    def total = historyInstance.size()


    [historyInstance: historyInstance,patientInstance: patientInstance,historyInstanceTotal: total]


    }
}
我在视图上有这个代码

    <g:each in="${historyInstance}" var="historyInstances" status="i">
      ...
    </g:each>

    <div class="pagination">
        <g:paginate  total="${historyInstanceTotal}"/>
    </div>
我使用了参数,我尝试了一切,但没有结果,它总是在视图中显示整个历史记录集。

您需要将参数传递给正在使用的查找程序,否则它将不知道如何分页。该标记仅用于显示分页链接,而不是实际执行分页。此外,总数将需要使用countBy,因为结果集将限于当前结果页

def historyInstance = History.findAllByPatient(patientInstance, params)
def total = History.countByPatient(patientInstance)
您需要将参数传递给正在使用的查找程序,否则它将不知道如何分页。该标记仅用于显示分页链接,而不是实际执行分页。此外,总数将需要使用countBy,因为结果集将限于当前结果页

def historyInstance = History.findAllByPatient(patientInstance, params)
def total = History.countByPatient(patientInstance)

可能重复的可能重复的可能重复的没有countAllBy,我尝试过,但它显示了一个错误,可能是另一种方式,而不是findAllBy,我听说paginate仅适用于ListFindAllBy,并列出域对象的两个返回列表。但是,当获取count History Instance.CountByPatientPaientInstance时,对我不起作用,History.CountByPatientPaientPaientInstance有。感谢您的关注,@BernardoThere不是CountalBy,我试过了,但它显示出一个错误,可能是另一种方式,而不是findAllBy,我听说paginate只处理listsfindAllBy,并列出域对象的两个返回列表。当获取count historyInstance.CountByPatientPaientPaientInstance对我不起作用,但是,History.CountByPatientPaientPaientInstance对我起作用。谢谢你捕捉到这一点,@Bernardo