Grails-跨控制器代码,对每个请求执行 [英] Grails - cross controller code, execute on every request

查看:78
本文介绍了Grails-跨控制器代码,对每个请求执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以在调用任何控制器动作之前执行一些代码?

Is there a way of executing some piece of code before any controller action gets called?

我需要基于get参数的值设置会话变量,而无需考虑调用哪个控制器.

I need to set a session variable based on the value of a get parameter, without taking into account which controller gets called.

当然,一旦完成此处理,请求就必须按照其正常方式执行相应的控制器/操作.

Of course, once this processing is done, the request needs to follow its normal way to the corresponding controller/action.

谢谢

推荐答案

听起来像您想使用例如 grails-app/conf/MyFilter.groovy

class MyFilter {
    def filters = {
        extractSomething(controller: '*', action: '*') {
            before = {
                session.setAttribute('foo', params['paramName'])
            }
        }
    }
}

这篇关于Grails-跨控制器代码,对每个请求执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆