springBoot默认模板引擎Thymeleaf简介

由于springBoot默认的是jar包形式,所以不支持,jsp。因此我们需要模板引擎。

JSP、Velocity、Freemarker、Thymeleaf模板引擎的大致原理:页面+数据交给模板引擎(写一个页面模板,里面一些值是动态的,我们用表达式形式,表达。例如下图中的template中的${user},数据来自Data),模板引擎通过数据解析表达式,写到对应位置。最终显示出去。

市场上大概有5种,而spring默认选择Thymeleaf(语法更简单,功能更强大)

使用:

 1、引入thymeleaf;注意(默认的是2.1.6的版本)因此我们需要切换版本

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

2.切换版本:注意,thymeleaf的主程序与layout版本的对应关系(3版本对应2)

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

猜你喜欢

转载自blog.csdn.net/weixin_42338186/article/details/81412906