Thymeleaf template engine Practical Guide (regularly updated)
thymeleaf is a powerful template engine, and seamless integration with Spring Boot, in place of Spring MVC + JSP choice
Configuration
Maven configuration
If you are using Spring Boot 2.1.x version, so no additional configuration
pom.xml
<!--默认与Spring Boot 保持一致-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
If you are using Spring Boot 1.15.x, then there will be a small crater, which is about Thymeleaf parser (when resolving single-label may be prompted to no end tag), so you need to configure the following in pom.xml some configurations ,details as follows:
...
<properties>
...
<!--这里-->
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
...
</properties>
...
Namespaces
Thymeleaf want to use a template engine parses the HTML page needs to be introduced in the namespace thymeleaf page, you can use thymeleaf unique tag
namespace:http://www.thymeleaf.org
Example:
<!DOCTYPE html>
<!--这里↓↓↓↓↓↓↓↓-->
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
<meta charset="UTF-8" />
<title>示例</title>
</head>
<body>