在Grails 3.x中将参数从控制器传递给Interceptor的after()操作

时间:2016-11-23 16:19:06

标签: grails

我需要将一个param从控制器传递给Interceptor的after()动作。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

您在拦截器关闭之前有可用的请求和响应对象,但请求/响应对象的范围在执行闭包后完成,该模型对象作为参数。

class YourInterceptor {
    boolean before(){
    //code before reaching respective controller
        return true
    }
   //this part is executed before the view is rendered,
    def afterInterceptor = { model ->
        def myParam = model.yourParam;
    }
}

You can set the model object used above in your controller as
public class YourController {
  //your controller logic
[yourParam: paramValue] // this map is the model object which contains `the data for your view, this object is the model object that is used in after closure of interceptor.`
}