什么是Thymeleaf模板引擎
- Thymeleaf是适用于Web和独立环境的现代服务器端Java模板引擎
- 模板引擎:为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的html文档。
- Thymeleaf能够快速整合入Springboot,使用方便快捷。
- 自我理解就是一个可复用性强的前端模板框架
引入Thymeleaf
<!--thymeleaf-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
使用Thymeleaf需要引入命名空间约束
xmlns:th="http://www.thymeleaf.org"
常用标签
th:id 替换id <input th:id="'xxx' + ${collect.id}"/>
th:text 文本替换 <p th:text="${collect.description}">description</p>
th:utext