LoginSignup
0
0

More than 5 years have passed since last update.

[Grails3]Interceptorでコントローラを取得するTraitを作ってみる

Last updated at Posted at 2015-06-12

Traitを使ってみたかった

こちらの記事を参考に、コントローラ名からコントローラのインスタンスを取得する部分をTraitにしてみただけです。

コード


trait GetController {

  def getController() {
    String controllerName = params?.controller
    if (!controllerName){
       return null
    }
    def artifact = grailsApplication
            .getArtefactByLogicalPropertyName("Controller", controllerName)
    applicationContext.getBean(artifact.clazz.name)
  }

}

class XXXInterceptor implements GetController {

  boolean before() {
    def controllerInstance = getController()
  }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0