在grails中过滤带偏移量的集合 [英] Filtering a collection with offset in grails

查看:106
本文介绍了在grails中过滤带偏移量的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用findAll在grails中过滤一个集合,所以我只在他的字段estado中获得具有特定值的实例。

我有这样的东西:

  trabajos.findAll({it.estado.equals(Pago)})

问题是我不知道如何分页返回的集合。

我看了一下grails文档,发现这个

  Book.findAll(Map queryParams,Closure whereCriteria)

但是当我尝试时

  trabajos.findAll([offset:0],{it。我收到以下异常:

 方法没有签名:java.util.ArrayList.findAll()适用于参数类型:(java.util.LinkedHashMap,com.publidirecta.PersonalController $ _show_closure2)values:[[offset:0],com.publidirecta.PersonalController$_show_closure2@a6bdb0] 
可能的解决方案:f findAll(),findAll(),findAll(groovy.lang.Closure),findAll(groovy.lang.Closure),find(),find()`

这是为什么要实现某种分页方式,为什么或者我需要手动执行?


解决方案

我猜你是麻烦的2件事:grails和groovy。
Book.findAll(Map queryParams,Closure whereCriteria)
但是在 trabajos.findAll({it.estado.equals(Pago())是一个数据库中的查找器,它是grails的东西,你可以传递max参数。 )})您正在尝试在列表中查找。这是很时髦的事情。查看更多详情此处 here



如果您尝试从数据库中获取对象,请像这样使用



Book.findAll(Map queryParams,Closure whereCriteria)



如果是一个对象列表,请使用下面的代码:

  def filtered = trabajos.findAll ({it.estado.equals(Pago)})
def result = filteredList [offset ..offset + max< filtered.size()? offset + max:filtered.size()]


I'm trying to filter a collection in grails with findAll so I only get the instances with a certain value in his field "estado".
I have something like this:

trabajos.findAll({it.estado.equals( "Pago")})

The problem is I dont know how to paginate the returned collection.
I took a look at grails documentation and found this

Book.findAll(Map queryParams, Closure whereCriteria)

but when I try it

trabajos.findAll([offset: 0], {it.estado.equals("Pago")})

I get the following exception

No signature of method: java.util.ArrayList.findAll() is applicable for argument types:       (java.util.LinkedHashMap, com.publidirecta.PersonalController$_show_closure2) values: [[offset:0], com.publidirecta.PersonalController$_show_closure2@a6bdb0] 
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(groovy.lang.Closure), find(), find()`  

Is this a why to achieve some sort of pagination this why or would I have to do it manually?

解决方案

I guess you are muss 2 things: grails and groovy.
Book.findAll(Map queryParams, Closure whereCriteria) - is a finder in database, it's grails thing and you can pass max param in it.
But in trabajos.findAll({it.estado.equals( "Pago")}) you are trying to find in list. It's groovy thing. See more details
here and here

If you try to get objects from database, use like this

Book.findAll(Map queryParams, Closure whereCriteria).

If it's a list of objects use something like this:

def filtered = trabajos.findAll({it.estado.equals( "Pago")})
def result = filteredList[offset..offset+max < filtered.size() ? offset+max : filtered.size()]

这篇关于在grails中过滤带偏移量的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆