Thymeleaf

thymeleaf是一个xml、xhtml、html5模板引擎,可用于Web与非Web环境的应用开发,是一个开源的Java库

  • Thymeleaf提供了一个用于整合Spring MVC的可选模块,在应用开发中,你可以使用Thymeleaf来完全代替JSP或其他模板引擎,如Velocity、FreeMarker等。
  • 主要目标在于提供一种可被浏览器正确显示的、格式良好的模板创建方式,因此也可以用作静态建模。
    它的特点便是:开箱即用,Thymeleaf允许您处理六种模板,每种模板称为模板模式:
    - - XML 、有效的XML 、XHTML 、 有效的XHTML 、 HTML5 、 旧版HTML5
**SpringBoot整合thymeleaf**
步骤:
-  1、创建一个sprinboot项目
-  2、添加thymeleaf和spring web的起步依赖
-  3、编写html 使用thymleaf的语法获取变量对应后台传递的值
-  4、编写controller 设置变量的值到model中
加入对应依赖:
       <!--web起步依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

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

创建html

<html xmlns:th="http://www.thymeleaf.org">:这句声明使用thymeleaf标签
<p th:text="${hello}"></p>:这句使用 th:text=“${变量名}” 表示 使用thymeleaf获取文本数据,类似于EL表达式。

修改application.yml配置

spring:
  thymeleaf:
    cache: false

Thymeleaf基本语法
1、th:action

2、th:each

3、Map输出

4、数组输出

5、Date输出

6、th:if条件

7、使用javascript

8、字符拼接 使用 ||

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值