博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
thymeleaf 基础语法
阅读量:6226 次
发布时间:2019-06-21

本文共 7250 字,大约阅读时间需要 24 分钟。

  hot3.png

1、模板包含

1.1、同一个页面

此处是模版

1.2、同一个页面带参数

...

1.3、模板定义与调用 在不同页面

        定义模板 footer.html,示例如下:

© 2016 CodeApe.cn
基于ID属性的模板

        调用文件,示例如下:

基于DOM选择器的模板引用,调用格式:th:include="templatename::domselector" 

templatename是要引入页面的路劲加上去掉后缀的名称,例如footer.html页面建立在/WEB-INF/templates/footer.html,所以templatename为footer;domselector就是dom选择器,即为th:fragment中的值,或是选择id

2、页面控制语法

1、IF语法

此处是使用spring security的前提下,判断当前用户使用拥有 admin权限。

2、日期格式、组件提取等

${#dates.format(date)}${#dates.arrayFormat(datesArray)}${#dates.listFormat(datesList)}${#dates.setFormat(datesSet)}${#dates.format(date, 'dd/MMM/yyyy HH:mm')}${#dates.arrayFormat(datesArray, 'dd/MMM/yyyy HH:mm')}${#dates.listFormat(datesList, 'dd/MMM/yyyy HH:mm')}${#dates.setFormat(datesSet, 'dd/MMM/yyyy HH:mm')}${#dates.day(date)}${#dates.month(date)}${#dates.monthName(date)}${#dates.monthNameShort(date)}${#dates.year(date)}${#dates.dayOfWeek(date)}${#dates.dayOfWeekName(date)}${#dates.dayOfWeekNameShort(date)}${#dates.hour(date)}${#dates.minute(date)}${#dates.second(date)}${#dates.millisecond(date)}${#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,millisecond)}${#dates.createNow()}${#dates.createToday()}

3、日历

${#calendars.format(cal)}${#calendars.arrayFormat(calArray)}${#calendars.listFormat(calList)}${#calendars.setFormat(calSet)}${#calendars.format(cal, 'dd/MMM/yyyy HH:mm')}${#calendars.arrayFormat(calArray, 'dd/MMM/yyyy HH:mm')}${#calendars.listFormat(calList, 'dd/MMM/yyyy HH:mm')}${#calendars.setFormat(calSet, 'dd/MMM/yyyy HH:mm')}${#calendars.day(date)}${#calendars.month(date)}${#calendars.monthName(date)}${#calendars.monthNameShort(date)}${#calendars.year(date)}${#calendars.dayOfWeek(date)}${#calendars.dayOfWeekName(date)}${#calendars.dayOfWeekNameShort(date)}${#calendars.hour(date)}${#calendars.minute(date)}${#calendars.second(date)}${#calendars.millisecond(date)}${#calendars.create(year,month,day)}${#calendars.create(year,month,day,hour,minute)}${#calendars.create(year,month,day,hour,minute,second)}${#calendars.create(year,month,day,hour,minute,second,millisecond)}${#calendars.createNow()}${#calendars.createToday()}

4、格式化数字对象

${#numbers.formatInteger(num,3)}${#numbers.arrayFormatInteger(numArray,3)}${#numbers.listFormatInteger(numList,3)}${#numbers.setFormatInteger(numSet,3)}${#numbers.formatInteger(num,3,'POINT')}${#numbers.arrayFormatInteger(numArray,3,'POINT')}${#numbers.listFormatInteger(numList,3,'POINT')}${#numbers.setFormatInteger(numSet,3,'POINT')}${#numbers.formatDecimal(num,3,2)}${#numbers.arrayFormatDecimal(numArray,3,2)}${#numbers.listFormatDecimal(numList,3,2)}${#numbers.setFormatDecimal(numSet,3,2)}${#numbers.formatDecimal(num,3,2,'COMMA')}${#numbers.arrayFormatDecimal(numArray,3,2,'COMMA')}${#numbers.listFormatDecimal(numList,3,2,'COMMA')}${#numbers.setFormatDecimal(numSet,3,2,'COMMA')}${#numbers.formatDecimal(num,3,'POINT',2,'COMMA')}${#numbers.arrayFormatDecimal(numArray,3,'POINT',2,'COMMA')}${#numbers.listFormatDecimal(numList,3,'POINT',2,'COMMA')}${#numbers.setFormatDecimal(numSet,3,'POINT',2,'COMMA')}${#numbers.sequence(from,to)}${#numbers.sequence(from,to,step)}

5、字符串处理

${#strings.isEmpty(name)}${#strings.arrayIsEmpty(nameArr)}${#strings.listIsEmpty(nameList)}${#strings.setIsEmpty(nameSet)}${#strings.defaultString(text,default)}${#strings.arrayDefaultString(textArr,default)}${#strings.listDefaultString(textList,default)}${#strings.setDefaultString(textSet,default)}${#strings.contains(name,'ez')}${#strings.containsIgnoreCase(name,'ez')}${#strings.startsWith(name,'Don')}${#strings.endsWith(name,endingFragment)}${#strings.indexOf(name,frag)}${#strings.substring(name,3,5)}${#strings.substringAfter(name,prefix)}${#strings.substringBefore(name,suffix)}${#strings.replace(name,'las','ler')}${#strings.prepend(str,prefix)}${#strings.append(str,suffix)}${#strings.toUpperCase(name)}${#strings.toLowerCase(name)}${#strings.arrayJoin(namesArray,',')}${#strings.listJoin(namesList,',')}${#strings.setJoin(namesSet,',')}${#strings.arraySplit(namesStr,',')}${#strings.listSplit(namesStr,',')}${#strings.setSplit(namesStr,',')}${#strings.trim(str)}${#strings.length(str)}${#strings.abbreviate(str,10)}${#strings.capitalize(str)}${#strings.unCapitalize(str)} ${#strings.capitalizeWords(str)} ${#strings.capitalizeWords(str,delimiters)}${#strings.escapeXml(str)} ${#strings.escapeJava(str)}${#strings.escapeJavaScript(str)} ${#strings.unescapeJava(str)} ${#strings.unescapeJavaScript(str)}${#strings.equals(str)}${#strings.equalsIgnoreCase(str)}${#strings.concat(str)}${#strings.concatReplaceNulls(str)}

6、对象处理

${#objects.nullSafe(obj,default)}${#objects.arrayNullSafe(objArray,default)}${#objects.listNullSafe(objList,default)}${#objects.setNullSafe(objSet,default)}

7、布尔值相关

${#bools.isTrue(obj)}${#bools.arrayIsTrue(objArray)}${#bools.listIsTrue(objList)}${#bools.setIsTrue(objSet)}${#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)}

8、数组相关

${#arrays.toArray(object)}${#arrays.toStringArray(object)}${#arrays.toIntegerArray(object)}${#arrays.toLongArray(object)}${#arrays.toDoubleArray(object)}${#arrays.toFloatArray(object)}${#arrays.toBooleanArray(object)}${#arrays.length(array)}${#arrays.isEmpty(array)}${#arrays.contains(array, element)}${#arrays.containsAll(array, elements)}

9、list集合相关

${#lists.toList(object)}${#lists.size(list)}${#lists.isEmpty(list)}${#lists.contains(list, element)}${#lists.containsAll(list, elements)}${#lists.sort(list)}${#lists.sort(list, comparator)}

10、set集合相关

${#sets.toSet(object)}${#sets.size(set)}${#sets.isEmpty(set)}${#sets.contains(set, element)}${#sets.containsAll(set, elements)}

11、map集合相关

${#maps.size(map)}${#maps.isEmpty(map)}${#maps.containsKey(map, key)}${#maps.containsAllKeys(map, keys)}${#maps.containsValue(map, value)}${#maps.containsAllValues(map, value)}

12、聚集,聚合

${#aggregates.sum(array)}${#aggregates.sum(collection)}${#aggregates.avg(array)}${#aggregates.avg(collection)}

13、获取外部信息内部变量

${#messages.msg('msgKey')}${#messages.msg('msgKey', param1)}${#messages.msg('msgKey', param1, param2)}${#messages.msg('msgKey', param1, param2, param3)}${#messages.msgWithParams('msgKey', new Object[] {param1, param2, param3, param4})}${#messages.arrayMsg(messageKeyArray)}${#messages.listMsg(messageKeyList)}${#messages.setMsg(messageKeySet)}${#messages.msgOrNull('msgKey')}${#messages.msgOrNull('msgKey', param1)}${#messages.msgOrNull('msgKey', param1, param2)}${#messages.msgOrNull('msgKey', param1, param2, param3)}${#messages.msgOrNullWithParams('msgKey', new Object[] {param1, param2, param3, param4})}${#messages.arrayMsgOrNull(messageKeyArray)}${#messages.listMsgOrNull(messageKeyList)}${#messages.setMsgOrNull(messageKeySet)}

14、处理可能重复的id属性

${#ids.seq('someId')}${#ids.next('someId')}${#ids.prev('someId')}

3、其他

1、在JS中查看对象

 

转载于:https://my.oschina.net/ruoli/blog/1605664

你可能感兴趣的文章
mininet和floodlight搭建openflow系统
查看>>
Webkit内核的浏览器中用CSS3+jQuery实现iphone滑动解锁效果(译)
查看>>
常与同好争高下:互联网创业的8条忠告
查看>>
我的友情链接
查看>>
用脚本检测局域网络是否可以ping通
查看>>
jmeter安装
查看>>
我的友情链接
查看>>
HTTP响应代码(Response Status Code)中文详解
查看>>
bootstrap-按钮的向下向上三角形-向上弹起的下拉菜单
查看>>
SQL Server 2017 AlwaysOn AG 自动初始化(四)
查看>>
phpcms V9 get 实现前台搜索结果分页
查看>>
磁盘配额
查看>>
O-3 WOL网络唤醒详解,随时随地打开电脑
查看>>
F(x)
查看>>
shell脚本整理
查看>>
再续伯努利欧拉错装信封问题
查看>>
可变多维数组组合算法
查看>>
使用Firefox的“HttpRequester”插件测试REST风格的webservice
查看>>
视图和索引
查看>>
论文解读:基于机器学习的知道推荐—Enlister
查看>>