天天看点

groovy grails 动态方法一例

//定义一个类

class GlobalService{

def grailsApplication

def propertyMissing(String name){

    grailsApplication.mainContext.getBean("${name}Service")

}

}

class MyService{}

class MyController{

   def globalService

   def index = {

        println globalService.my//此时会打印 myService这个对象

   }

}

继续阅读