grails override redirect controller method

那年仲夏 提交于 2019-12-03 16:12:11

Yes, the signature is wrong - redirect takes a single Map parameter (see the declaration in org.codehaus.groovy.grails.plugins.web.ControllersGrailsPlugin.registerControllerMethods())

So it should be

controllerClass.metaClass.redirect = { Map args ->
   // pre-redirect logic
   oldRedirect.invoke delegate, args
   // post-redirect logic
}

Also note that if you want the redirect method override to be reapplied after modifying the source code of a controller, you need to do the following:

def watchedResources = [
  "file:./grails-app/controllers/**/*Controller.groovy"]

def onChange = { event ->
  if(!(event.source instanceof Class)) return

  if(application.isArtefactOfType(ControllerArtefactHandler.TYPE, event.source))
  {
    replaceRedirectMethod(application.getArtefact(ControllerArtefactHandler.TYPE,
                                                  event.source.name))
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!