Grails findByAll with params不起作用

时间:2013-07-13 08:01:54

标签: list grails params

我尝试从我的控制器显示自定义列表,但是当我想使用分页时, 它不起作用:例如,如果我想要显示10个条目(params.max = Math.min(max?:10,100)),在我的gsp列表视图中,所有条目都显示在同一页面中。我也注意到我有分页但是当我使用它时,我仍然显示所有条目。 我的代码

def user = User.findByLogin("John")
List MyList

switch (userView){

 case "mylist":

    params.sort="date"
    params.order="desc"
    params.max = Math.min(max ?: 10, 100)

    MyList = DS.findAllByCpCreator(user,[params:params])

 case ...

...

def DSList = MyList                     
def DSCount = MyList.size()
[DSInstanceList: DSList, DSInstanceTotal: DSCount,userView:userView]

在gsp视图中,我修改了这样的分页:

<div class="pagination">
    <g:if test="${userView!=null}">
        <g:paginate total="${DSInstanceTotal}" params="${[q:userView]}" />  
    </g:if>
    <g:else>
        <g:paginate total="${DSInstanceTotal}" />
    </g:else>
</div>

1 个答案:

答案 0 :(得分:0)

在你的行动中,你传递了findAll *地图的地图,它应该是:

MyList = DS.findAllByCpCreator(user, params)

编辑:实际上您的视图标记正常

对于计数,您应该使用:http://grails.org/doc/2.2.x/ref/Domain%20Classes/countBy.html

DSCount = DS.countByCpCreator(user)
相关问题