我有域“国家”并且在 list.gsp 上我有带有输入字段的搜索块。第一个问题是当我尝试在我的列表中使用分页时,总是显示所有结果,在这种情况下,我找到了解决方案,我只发送了 10 个值进行显示(如果你知道另一种解决方案,请告诉我)。我的搜索看起来是这样的:
    def search = {
       if(query){
           def srchResults = searchableService.search(query, params)
           def result =  Country.executeQuery("select  new map(a.name as name, a.datacenter as datacenter) from Country a where a.name like '%"+ params.q + "%'")
           if (params.offset)
           {
               x = params.offset.toInteger()
               y = Math.min(params.offset.toInteger()+9, result.size()-1)
           } else
            {
            x = 0
            size = result.size() - 1
            y = Math.min(size, 9)
             }     
           def q=params.q
          [countryInstanceList: result.getAt(x .. y), countryInstanceTotal:result.size(), q:params.q]
       }else{
           redirect(action: "list")
       }
   }
现在我有另一个问题,当我按下下一页时,我的搜索字段中的参数正在清理,结果为空。我试图将字段值作为参数发送,但我做错了什么。
我的搜索页面如下所示:
<g:form action="search">
            <div class="search" >
                Search Country
                <g:hiddenField name="q" value="${params.q}" />
                <input type="text" name="q" value="${params.q}" />
                <input type="submit" value="Search"/>
            </div>
        </g:form>
…………