RaceTrackTagLib.groovy(放到grails-app\taglib目录下)
class RaceTrackTagLib {
def formatDate = { attrs ->
def date = attrs.get('date')
if (!date) {
date = new Date()
}
def format = attrs.get('format')
if (!format) {
format = "yyyy-MM-dd HH:mm:ss z"
}
out << new Java.text.SimpleDateFormat(format).format(date)
}
def formatNumber = { attrs ->
def number = attrs.get('number')
if (!number) {
number = new Double(0)
}
def format = attrs.get('format')
if (!format) {
format = "0"
}
out << new Java.text.DecimalFormat(format).format((Double)number)
}
}
页面中使用
<g:formatDate date="${race.startDateTime}" format="yyyy-MMM-dd HH:mm"/>
<g:formatNumber number="${race.distance}" format="##0.00 mi"/>
posted on 2008-04-02 00:28
周锐 阅读(607)
评论(0) 编辑 收藏 所属分类:
Groovy&Grails