thymeleaf模板部分知识(持续更新)
来源:互联网 发布:地暖好吗知乎 编辑:程序博客网 时间:2024/06/15 19:03
由于视图层一直用的是jsp,在初次接触模板时难免遇到一些不为人知的知识点,通过查文档,google,请教前辈,可以慢慢积累一些知识点,在此记录,以方便后来人查阅,也进一步巩固这些知识点。
1)a标签href属性的路径带多参数,还有一种拼接,没有这个清爽
<a th:href="@{/manage/permission/update(id=${p.id},page=${page})}" th:text="${p.description}"></a>
2)if else判断
<span th:if="${level.isUse==1}" th:text="已使用"></span><span th:unless="${level.isUse==1}" th:text="未使用"></span>
3)在js代码块中获得Model中存储的数据
var name = '[[${name}]]';
4)格式化日期,此模板已经封装好的
<td th:text="${#calendars.format(admin.createTime,'yyyy-MM-dd HH:mm:ss')}"></td><span th:text="${#dates.format(admin.createTime, 'yyyy-MM-dd HH:mm:ss')}"></span>
5)添加点击事件,调用js函数
<a href="#editModal" th:onclick="'javascript:edit('+${user.id}+');'">修改</a>
6)thymeleaf中使用三元运算符
<span th:text="${sex eq 0 ? '女' : '男'}"></span>
7)获取list长度
<span th:text="${#lists.size(users)}"></span>
8)数字格式化
<span th:text="${#numbers.formatDecimal(price, 0, 2)}"></span><!--保留两位小数,整数位自动--><span th:text="${#numbers.formatDecimal(money, 3, 2)}"></span><!--保留两位小数,3位整数位-->
9)thymeleaf中循环纯数字
<th:block th:each="i:${#numbers.sequence(1,5)}"> <h3 th:text="${i}"></h3></th:block>
10)引用公共页面,在要引用的代码块上使用th:fragment做标记,在主页面使用th:include引用
要引用的代码块
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"><div th:fragment="footer"><span class="footer-brand"><strong class="text-danger">日报</strong> 后台管理</span><p class="no-margin">© 2017 <strong>宁波日报</strong>. 版权所有.</p></div></html>主页面,下面标签中第一个footer是模板名,第二个是标记名
<footer class="footer" th:include="footer :: footer"> <!-- 引用底部 --></footer>
0 0
- thymeleaf模板部分知识(持续更新)
- [自用模板]持续更新!
- javascript部分细节(持续更新)
- css部分细节(持续更新)
- hgame17_re 部分writeup(持续更新)
- 收集小知识 持续更新...
- android小知识(持续更新)
- 持续更新 风机相关知识
- 知识补充(持续更新)
- JS知识整理(持续更新)
- 比赛模板(持续更新中)
- thymeleaf模板
- Thymeleaf 模板
- thymeleaf 模板
- thymeleaf 模板
- 排序算法持续更新(部分转载)
- Hibernate-部分知识点概述(持续更新)
- Spring-部分知识点概述(持续更新)
- Apache FileUpload 文件上传组件API解读-2
- 设计模式之构造模式
- Java中CAS详解
- SQL Server 用户只看到自己有权限的库
- 比较Collection 和Collections的区别,Array与Arrays的区别
- thymeleaf模板部分知识(持续更新)
- ES权威指南_06_Modeling Your Data_01 Handling Relationships
- P1118 数字三角形(技巧)
- ES权威指南_06_Modeling Your Data_02 Nested Objects
- ASP.NET Web Pages – C# 和 VB 中的例子
- C#后端得到前台GridView的每行的主键值ID
- ES权威指南_06_Modeling Your Data_03 Parent-Child Relationship
- 【学习笔记】系列十六:Ant单元测试TestNG
- jquery的$().each,$.each的区别