SpringBoot推荐的Thymeleaf

1.引入依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

2.切换thymeleaf版本

<properties>
        <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
        <!-- 布局功能的支持程序  thymeleaf3主程序  layout2以上版本 -->
        <!-- thymeleaf2   layout1-->
        <thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
  </properties>

3.Thymeleaf使用

只要我们把HTML页面放在classpath:/templates/,thymeleaf就能自动渲染;

①导入thymeleaf的名称空间

<html lang="en" xmlns:th="http://www.thymeleaf.org">

4.语法规则

th:text;改变当前元素里面的文本内容

th:任意html属性;来替换原生属性的值

原文地址:https://www.cnblogs.com/gxlaqj/p/11678634.html