thymeleaf模板部分知识(持续更新)
2017-04-22 00:00
281 查看
由于视图层一直用的是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>
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>
相关文章推荐
- thymeleaf模板部分知识(持续更新)
- Java小知识(杂、持续更新)
- 《叩响C#之门》接触窗体编程 基本知识 和 自动产生的部分代码分析(11月7日更新)
- Android之基本常见知识(持续更新)
- ci基础知识总汇(持续更新)
- Python初学笔记——琐碎知识,based on 2.7.3,持续更新中
- TCP/IP详解笔记(TCP部分持续更新中)
- java基础知识,持续更新
- MFC开发小知识(持续更新)
- C/C++文档注释神器——Doxygen常用知识整理(持续更新)
- C的一些知识【持续更新】
- 项目开发总结:前端开发部分总结[兼容性、DOM操作、跨域等](持续更新)
- C/C++文档注释神器——Doxygen常用知识整理(持续更新)
- FreeBSD与linux的部分命令对比(持续更新中)
- 安卓开发一些界面控件的小例子(部分内容转载,持续更新ING)
- 关于《ASP.NET 3.5 揭秘 卷1》里的部分错误(持续更新)
- 前端开发部分总结[兼容性、DOM操作、跨域等](持续更新)
- jQuery学习总结之基础知识----持续更新中
- .NET基础知识问题汇总(持续更新中)
- 杂碎小知识(持续更新)