grails自定义标签

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

class LuguaTagLib{
//指定命名空间
static namespace="lg"
//指定标签的返值为object
static returnObjectForTags = ['now']

def now = { attr->
    new Date()
}

def jsMap = [core:"<script type='text/javascript' src='/lugua/js/jquery.js'></script>",
ui:"<script type='text/javascript' src='/lugua/js/jquery.ui.js'></script>"]

//js引用助手
def js = { attr ->
    def includeList = attr.include.tokenize(',')
    out << includeList.collect{ jsMap[it] }.join('\n')
}

}

标签调用方式:<lg:js include='core,ui'/>或者lg.js(include:'core')
lg.now
在grails的控制器,和页面中都可以直接调用自定义标签。