如何替换支架控制器操作并仍然在 Grails 中调用原始控制器操作?
我需要“覆盖”控制器中的脚手架操作,执行一些操作,然后调用原始操作。我更喜欢使用动态生成的方法,而不必剪切和粘贴代码。
class AccountController {
static scaffold = Account
def list = {
// do something
// invoke "super.list" i.e. the dynamically generated scaffold
}
有什么想法吗?
I need to 'override' a scaffolded action in a controller, do some stuff and then invoke the original. I would prefer to use the dynamically generated method and not have to cut and paste the code.
class AccountController {
static scaffold = Account
def list = {
// do something
// invoke "super.list" i.e. the dynamically generated scaffold
}
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以考虑使用拦截器或过滤器(为什么?更干净)
控制器拦截器
http://grails.org/doc/ latest/guide/6.%20The%20Web%20Layer.html#6.1.5
过滤器 http://grails.org/doc/latest/guide/ 6.%20The%20Web%20Layer.html#6.6
You could consider using an interceptor or a filter instead (why? much cleaner)
Controller Interceptors
http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.1.5
Filters http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.6
在新控制器中完成所需操作后,只需重定向到原始控制器即可。大致如下:
希望这有帮助
Once you've done whatever you need to in your new controller, simply redirect to the original. Something along the lines of:
Hopefully this helps