如何使用grails分页



我是grails的新手,我曾尝试使用grails文档中的grails分页标记,我的index.gsp 中有一个搜索表单

我不知道如何传递params.max和params.offset我只使用一个动作索引

我有一个索引操作,其中包含列出一些书籍的查询:

params.max = 10
params.offset = 0
def author=params.author // i get the input search params
def max = 10
def offset = 0
if(params.max){
    max = params.max
}
if(params.offset){
    offset = params.offset
}
def bookPagin=Book.createCriteria().list {      
    eq("author", author)}
    maxResults(max)
    firstResult(offset )
}

这是我的index.gsp:中的分页标记

 <g:paginate controller="displayBook" action="index" total="${bookPagin.size()}" params="[author:author]"/>

现在,这段代码显示前10个结果,但当我点击第二个页面时它不需要输入author params,尽管我在GET请求中输入了author param,但还有其他解决方案吗?

以下是我的操作方法…

def searchString = "${params.author}%"
def searchResults = Book.findAllByAuthorLike(searchString, params) // max, offset automatically handled
def total = Book.countByAuthorLike(searchString)
render (model:[searchResults: searchResults, total: total])

在GSP中,使用迭代searchResults

<g:each var="book" in="${searchResults}">...

之后包括:

 <g:paginate controller="displayBook" action="index" total="${total}"/>

最新更新