Thymeleaf模板引擎
文档地址:https://www.thymeleaf.org/documentation.html
相关博客:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
spring:
thymeleaf:
# 关闭缓存
cache: false
# 设置字符集
encoding: UTF-8
语法示例
项目开发笔记
Thymeleaf时间格式转换
${#dates.format(时间数据,'时间格式')}
例:
${#dates.format(curr.date,'yyyy-MM-dd')}
根据数据库和本地路径显示图片
相关博客:
对单条数据操作及传值
相关博客:
获取项目名称(context-path)
在script标签中写
var ctx = [[@{/}]];
然后在html标签中就可以引用ctx变量了
带参数跳转页面
相关博客:
<a th:href="@{/second(slid=${second.slid},sname=${second.name})}">
封装公共代码块
创建空html文件,空的文件,不需要引入
thymeleaf命名空间
将需要封装的公共代码如 head标签里面的引入css和js文件等代码扔进去
在封装的公共代码的最外层标签上添加属性
th:fragment=""
,引号内部为唯一标识引用公共代码,
<th:block th:insert="公共代码页地址 :: 公共代码唯一标识"/>
公共代码页地址指的是mapping地址
关于传参
封装时:th:fragment="公共代码唯一标识(param)"
调用时:th:insert="公共代码唯一标识('HelloWorld')"
公共代码块内部使用形参通过${param}
使用,例如 th:text="${param}"
相关博客: