拥有以下域类:
class Message{
}
希望获得id
超过offset
的所有邮件:
def offset = params.offset
def messages = Message.list()
def subMessages = messages.findAll({offset, it ->
it.id > offset
}.curry(offset))
怎么了?
更新:我知道Message.list()
可以Message.list(params)
执行,但现在不重要了。
答案 0 :(得分:4)
def params = [offset: 2]
def messages = [[id: 1], [id: 2], [id: 3], [id: 4], [id: 5]]
def subMessages = messages.findAll({ it.id > params.offset })
assert subMessages == [[id: 3], [id: 4], [id: 5]]
(1..5).each { new Message(text: "${it}").save(failOnError: true) }
def params = [offset: "2"]
def offset = Integer.parseInt(params.offset)
def messages = Message.list()
def subMessages = messages.findAll({ it.id > offset })
assert subMessages == Message.findAllByIdGreaterThan(offset)