0
我尝试从我的控制器中显示一个自定义列表,但是当我想使用分页时, 不起作用:例如,如果我想显示10个条目(params。 max = Math.min(max?:10,100)),在我的gsp列表视图中,所有条目都显示在同一页面中。我也注意到我有分页,但是当我使用它时,我仍然显示了所有条目。 我的代码带参数的Grails findByAll不起作用
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>
我注意到“DSCount = MyList.size()”不正确,因为我需要获取有关用户名的所有条目。 因此,我还需要添加:“DSCount = DS.findAllByCpCreator(user) – Jils
对于count,您应该使用DS.countByCpCreator(用户)。http://grails.org/doc/2.2.x/ref/Domain %20Classes/countBy.html – ikumen