grails 2.0 与 1.3.7,flash.message 和 gsps 的工作方式

发布于 2024-12-12 19:00:50 字数 637 浏览 2 评论 0原文

在 Grails 1.3.7 中,默认控制器将生成如下代码,用于在域类的保存操作中显示 Flash 消息(只需注意赋值的开始,即“${ ):

 flash.message = "${message(code: 'default.created.message', args: [message(code: 'issue.label', default: 'Issue'), issueInstance.id])}"

在 Grails 2.0 中,这更改为

 flash.message = message(code: 'default.created.message', args: [message(code: 'issue.label', default: 'Issue'), issueInstance.id])

我们可以注意到差异是在 1.3.7 中,显然在 gsp 内部传递了一个字符串,在“gsp 编译时/运行时?”处。不Grails 2.0 中不再需要。这是因为 Groovy 功能​​发生了变化/改进吗?简而言之,我试图了解 Grails 的不同之处,即不再需要传递在 GSP 内部进行计算的消息,以及可以在哪些方面利用它。总体而言,Grails 2.0 中的这种差异/变化

谢谢,Ray 。

In Grails 1.3.7, the default controllers would produce code like the following for the display of flash messages in the save action for a domain class (just notice the start of the assignment, i.e. the "${ ):

 flash.message = "${message(code: 'default.created.message', args: [message(code: 'issue.label', default: 'Issue'), issueInstance.id])}"

In Grails 2.0, this is changed to

 flash.message = message(code: 'default.created.message', args: [message(code: 'issue.label', default: 'Issue'), issueInstance.id])

Where we can note the difference is at the start of the assignment. In 1.3.7, apparently a string is passed to be evaluated inside the gsp, at "gsp compile-time / run-time?". It appears this no longer needed in Grails 2.0. Is this because of a changed / improved Groovy capability? In short, I'm trying to understand what's different about Grails that passing a message that evaluates inside the GSP is no longer needed, and where one can take advantage of this difference/change in Grails 2.0 in general.

Thanks, Ray

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁拥 2024-12-19 19:00:50

我认为第二种(Grails 2.0)方式更干净一些。由于这两种替代方案本质上都计算为相同的字符串,因此在 GString 中计算的第一个替代方案似乎没有任何值。事实上,它是一个 GString,这意味着它将执行额外的表达式 (${...}) 处理(因此会稍微慢一些),而 Grails 2.0 版本只是直接进入消息标签库。

不知道为什么它最初是用第一种方式完成的...顺便说一句,我不认为 GString 内部的代码在 GSP 处理期间被评估 - 它是在 GString 分配给控制器中的 flash.message 时评估的(与 Grails 2.0 版本同时)...

I think the second (Grails 2.0) way is a bit cleaner. Since both the alternatives essentially evaluate to the same String, there doesn't seem to be any value in the first one being evaluated in a GString. The fact that it is a GString means that it'll be doing the extra expression (${...}) processing (so will be marginally slower), whereas the Grails 2.0 version just goes straight to the message taglib.

Not sure why it was originally done the first way... BTW, I don't think the code inside the GString is evaluated during the GSP processing - it is evaluated at the time the GString is assigned to flash.message in the controller (same time as the Grails 2.0 version)...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文