thymeleaf常用工具对象 博客分类: thymeleaf thymeleaf
程序员文章站
2024-03-17 12:33:34
...
这里讲一下thymeleaf常用的工具对象,其实和java中对应的方法大同小异。
(1)format时间格式化,支持集合转换
${#dates.format(date, 'yyyy-MM-dd hh:mm:ss')} ${#dates.arrayFormat(datesArray, 'yyyy-MM-dd hh:mm:ss')} ${#dates.listFormat(datesList, 'yyyy-MM-dd hh:mm:ss')} ${#dates.setFormat(datesSet, 'yyyy-MM-dd hh:mm:ss')}
(2)创建时间
${#dates.create(year,month,day)} ${#dates.create(year,month,day,hour,minute)} ${#dates.create(year,month,day,hour,minute,second)} ${#dates.create(year,month,day,hour,minute,second)} ${#dates.create(year,month,day,hour,minute,second,millisecond)} /**获得系统当前时间**/ ${#dates.createNow()} /**获得系统当前日期(没有时分秒)**/ ${#dates.createToday()}
(3)获取时间
//获得年 ${#dates.year(date)} //获得月 ${#dates.month(date)} //日 ${#dates.day(date)} //时分秒毫秒 ${#dates.hour(date)} ${#dates.minute(date)} ${#dates.second(date)} ${#dates.millisecond(date)} //获得星期 ${#dates.dayOfWeek(date)}
二、#strings
这里列举些常用的。
//转换字符串 ${#strings.toString(obj)} //字符长度 ${#strings.length(str)} //空值判断 ${#strings.isEmpty(str)} //设置默认值 ${#strings.defaultString(str,default)} //是否存在子串 ${#strings.contains(name,'ez')} //去除空格 ${#strings.trim(str)} //相等判断 ${#strings.equals(first, second)} ${#strings.equalsIgnoreCase(first, second)} //字符拼接 ${#strings.concat(values...)}
三、集合:#lists,#sets,#maps
${#lists.toList(object)} ${#lists.size(list)} ${#lists.isEmpty(list)} ${#lists.contains(list, element)} ${#lists.containsAll(list, elements)}
${#sets.toSet(object)} ${#sets.size(set)} ${#sets.isEmpty(set)} ${#sets.contains(set, element)} ${#sets.containsAll(set, elements)}
${#maps.size(map)} ${#maps.isEmpty(map)} ${#maps.containsKey(map, key)} ${#maps.containsAllKeys(map, keys)} ${#maps.containsValue(map, value)} ${#maps.containsAllValues(map, value)}
四、#bools
//true ${#bools.isTrue(obj)} ${#bools.arrayIsTrue(objArray)} ${#bools.listIsTrue(objList)} ${#bools.setIsTrue(objSet)} //false ${#bools.isFalse(cond)} ${#bools.arrayIsFalse(condArray)} ${#bools.listIsFalse(condList)} ${#bools.setIsFalse(condSet)} //集合所有项 && ${#bools.arrayAnd(condArray)} ${#bools.listAnd(condList)} ${#bools.setAnd(condSet)} //集合所有项 || ${#bools.arrayOr(condArray)} ${#bools.listOr(condList)} ${#bools.setOr(condSet)}
五、#aggregates
//求和 ${#aggregates.sum(collection)} //均值 ${#aggregates.avg(collection)}