2013-07-23 63 views
1

我已经一个星期试图解决这一问题分页,但不会有好结果,Grails的分页不工作

我有这个在我的控制器

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> 

我用params,最大的<g:paginate>,我什么都试过,但没有结果总是显示在视图中的一整套历史。

+0

可能重复[Grails的分页不起作用(http://stackoverflow.com/questions/17068081/grails-paginate-doesnt-work) – doelleri

回答

5

您需要将您的params传递给您正在使用的查找器,否则它将不知道如何分页。 <g:paginate>标记仅用于显示分页链接,而不是实际执行分页。此外total将需要使用countBy,因为结果集将被限制为当前页面的结果。

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

没有countAllBy,我试过,但它显示了一个错误,也许这是另一种方式,而不是'findAllBy',我听说分页只能用于列表 – ocespedes

+0

对不起,这是countBy – doelleri

+0

'findAllBy'和'list'都返回域对象的列表。 – doelleri