Grails 1.1 Web层 - Controller(控制器) 拦截器 - After 拦截器

为了定义一个在actions(操作)之后执行的拦截,可以使用afterInterceptor 属性:def afterInterceptor = { model -> println "Tracing action ${actionUri}" }after 拦截器把结果 model作为参数,所以,可以执行model或response的post操作.

after 拦截器 也可以在渲染之前修改Spring MVC ModelAndView 对象. 在这种情况下, 上面的示例变成:def afterInterceptor = { model, modelAndView -> println "Current view is ${modelAndView.viewName}" if(model.someVar) modelAndView.viewName = "/mycontroller/someotherview" println "View is now ${modelAndView.viewName}" }通过当前action(操作),允许基于被返回的model改变视图. 注意,如果action(操作)被拦截调用redirect 或render, modelAndView 可能为null.