为什么 .collect() 在以下 GString 中不起作用?
这在 GSP 页面中按预期工作:
<td>${Foo.findAllByBar(bar)}</td>
但是当添加收集语句时,代码会中断..
<td>${Foo.findAllByBar(bar).collect { it.name }}</td>
我的
Error 500: Could not parse script [...gsp]: startup failed,
...: 129: expecting '}', found ')'
@ line 129, column 196. 1 error`.
印象是任何有效的 Groovy 代码都可以放置在 GString ${ ... }
并得到正确评估/扩展。我缺少什么?
This works as expected in a GSP-page:
<td>${Foo.findAllByBar(bar)}</td>
But when adding a collect statement the code breaks ..
<td>${Foo.findAllByBar(bar).collect { it.name }}</td>
with
Error 500: Could not parse script [...gsp]: startup failed,
...: 129: expecting '}', found ')'
@ line 129, column 196. 1 error`.
I was under the impression that any valid Groovy code could be placed in a GString ${ ... }
and being correctly evaluated/expanded. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或者,您可以使用展开运算符:
Alternatively, you can use the spread operator:
GSP 解析器不喜欢
${...}
块中的}
。试试这个:The GSP parser doesn't like
}
within the${...}
block. Try this one: