groovy grails 动态方法一例

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

//定义一个类
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这个对象
   }
}