oce*_*des 1 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: 'patient.label', default: 'Patient'), id])
return
}
def historyInstance = History.findAllByPatient(patientInstance)
def total = historyInstance.size()
[historyInstance: historyInstance,patientInstance: patientInstance,historyInstanceTotal: total]
}
}
Run Code Online (Sandbox Code Playgroud)
我在视图上有这个代码
<g:each in="${historyInstance}" var="historyInstances" status="i">
...
</g:each>
<div class="pagination">
<g:paginate total="${historyInstanceTotal}"/>
</div>
Run Code Online (Sandbox Code Playgroud)
我用了params,最大的<g:paginate>,我尝试了一切但没有结果它总是在视图中显示整套历史.
您需要将您params的传递给您正在使用的查找器,否则它将不知道如何分页.该<g:paginate>标签只显示分页链接,而不是实际执行分页.还total需要使用a,countBy因为结果集将仅限于结果的当前页面.
def historyInstance = History.findAllByPatient(patientInstance, params)
def total = History.countByPatient(patientInstance)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1928 次 |
| 最近记录: |