29.SpringBoot学习笔记

引入Thymeleaf

Posted by Chen Xingxu on June 20, 2020

29.SpringBoot学习笔记–引入Thymeleaf

常见模板引擎

  • JSP
  • Velocity
  • FreeMarker
  • Thymeleaf

模板引擎原理图

Thymeleaf

引入 Thymeleaf

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

参考:https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/reference/html/appendix-dependency-versions.html#dependency-versions

参考 spring-boot-dependencies

<thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
<thymeleaf-extras-data-attribute.version>2.0.1</thymeleaf-extras-data-attribute.version>
<thymeleaf-extras-java8time.version>3.0.4.RELEASE</thymeleaf-extras-java8time.version>
<thymeleaf-extras-springsecurity.version>3.0.4.RELEASE</thymeleaf-extras-springsecurity.version>
<thymeleaf-layout-dialect.version>2.4.1</thymeleaf-layout-dialect.version>

Thymeleaf 相关的依赖版本均为当前最新,如果需要自定义版本,可以参考以下配置:

<properties>
    <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
    <!-- 布局功能的支持程序 -->
    <!-- 要选择与配置的thymeleaf适配的版本 -->
    <thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
</properties>

Thymeleaf 的官网:

https://www.thymeleaf.org

Thymeleaf 的代码仓库:

https://github.com/thymeleaf

thymeleaf-layout-dialect 的代码仓库:

https://github.com/ultraq/thymeleaf-layout-dialect