我必须显示项目列表及其详细信息。 Controller 看起来像这样
def showItems() {
def items = Item.list(offset:0, max:10, sort:"updatedOn", order:"desc")
render view : "show", model : [items : items]
}
这工作得很好,但问题是项目的“id”也被发送到我不想要的 gsp。如何将除“id”之外的所有项目详细信息从 Controller 发送到 gsp。
最佳答案
我不知道你为什么关心发送到 View 的 ID,但是,你可以这样做:
Item.list().collect { [prop1: it[prop1], ...] }
仅发送您想要的属性。
另一种选择:
Item.list().collect { it.subMap('key1', 'key2') }
还有更多 Groovy:
Item.list().collect{
def keys = it.keySet()
keys.remove('id')
it.subMap( keys )
}
关于java - 排除从 Grails 中的查询中检索 'id',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42950010/