此控制器将列出我数据库中的所有游戏。
def index() {
def platform = gameService.listPlatform()
def max = params.max ?: 10
def offset = params.offset ?: 0
def chosenPlatfrm = params.platform
def taskList = gameService.listGamePlat(chosenPlatfrm,max,offset)
def taskL = gameService.whatsHot(chosenPlatfrm,max,offset)
[games:taskL, bb:taskList, chosenPlatform:chosenPlatfrm, platforms:platform, gameCount:taskL.totalCount, gameCont:taskList.totalCount]
}
这就是我的index.gsp的外观。
<g:each in="${games}" status="i" var="game">
<g:if test="${game.averageRating != 0 }">
<g:link action="gameProfile"
params="${[gameTitle: "${game.gameTitle}"]}">
</g:link>
</g:if>
</g:each>
<div class="pagination" style="text-align: center;">
<g:paginate action="index" total="${gameCount}" offset="0" max="3" params="${params.max}"/>
</div>
我想将我的分页视图限制为每页仅 3 个项目。当index.gsp从我的索引控制器接收数据时,即使我有分页标签,它也会显示列表中的所有内容,但是当我单击页码时,它似乎工作正常。
我尝试在我的索引控制器中重定向,但它显示错误"错误重定向循环"
redirect(action: "index", params:[id:'',offset: '0', max: '3'])
如何正确显示我的 index.gsp?
我认为有一个
问题。尝试:
<g:paginate total="${gameCount}" />
而不是:
<g:paginate action="index" total="${gameCount}" offset="0" max="3" params="${params.max}"/>
另一个问题是在控制器中:你应该编写另一个函数来计算gameCount变量,它将计算每个分页视图中所有游戏的数量(所以没有偏移量和限制参数)。
当然重定向是错误的,因为你一遍又一遍地执行控制器的 index() 函数,所以请继续使用第一个提供的代码。