简体   繁体   English

带有参数的Grails findByAll不起作用

[英]Grails findByAll with params doesn't work

I try to display a custom list from my controller, but when I want to use the pagination, it doesn't work: for example if I want to diplay 10 entries (params.max = Math.min(max ?: 10, 100)), in my gsp list view all entries are displayed in the same page. 我尝试显示控制器中的自定义列表,但是当我想使用分页时,它不起作用:例如,如果我要显示10个条目(params.max = Math.min(max?:10,100 )),在我的gsp列表视图中,所有条目都显示在同一页面上。 I also noticed that I have pagination but I when I use it, I still have all entries displayed. 我还注意到我有分页,但是当我使用它时,仍然显示所有条目。 My code 我的密码

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]

In gsp view, I modified the pagination like this: 在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>

In your action, you are passing findAll* a map of maps, it should be: 在您的操作中,您要向findAll *传递一个地图,它应该是:

MyList = DS.findAllByCpCreator(user, params)

EDIT: actually your view tag is ok 编辑:实际上您的视图标记是可以的

For count, you should use: http://grails.org/doc/2.2.x/ref/Domain%20Classes/countBy.html 为了进行计数,您应该使用: http : //grails.org/doc/2.2.x/ref/Domain%20Classes/countBy.html

DSCount = DS.countByCpCreator(user)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM