【发布时间】:2016-04-29 11:52:57
【问题描述】:
在 grails 中,如果我这样做:
def someAction() {
//.......
flash.message = "some message"
[:]
}
然后在 someAction.gsp 中,它会显示 flash 消息。
但如果是这样的话:
def someAction() {
// ......
flash.message = "some message"
redirect uri: "${createLink(controller: 'someothercontroller', action: 'someotheraction')}"
}
那么在上述情况下,someotheraction.gsp 中将没有 flash.message。
我的问题是如何将 flash.message 从 someAction 传递到 someotheraction(可能在 someothercontroller 或同一个控制器中)。
我知道我可以执行params.flash = flash.message 之类的操作,在其他操作中使用此 params.flash 分配给那里的flash.message。然而,在这种方法中,我必须始终知道所有可能的重定向,而这些重定向可能并不总是发生。
那么有没有更好的,也许是“标准”的方式来保存 Flash 消息,直到最后一个重定向(最终呈现 gsp)?
【问题讨论】: