Kite的学习历程之SpringBoot中模板引擎thymelead

本文介绍了在SpringBoot项目中使用Thymeleaf模板引擎的过程,包括如何引入Thymelead,配置文件设置,以及Thymelead的基本语法如`th:text`和`th:`属性的用法。通过示例展示了在`success.html`页面的数据渲染,并提供了Thymelead官方文档链接,帮助读者深入理解其工作原理。
摘要由CSDN通过智能技术生成

Kite学习框架的第十六天

1.模板引擎

SpringBoot推荐使用Thymeleaf:语法简单,功能强大

1.1 引入themelead

字spring的官方文档
在这里插入图片描述
找到thymelead复制在pom.xml中进行导入
我们导入的是当前spring版本以来的对应的thymelead版本

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

1.2 thymelead的使用

只要我们把html页面放置在classpath:/template/ 下,thymelead就会自动进行渲染
使用方法:

  1. 导入命名空间
<html lang="en" xmlns:th="http://www.thymeleaf.org">
  1. thymelead语法
    <div  id="div01" class="myDiv" th:id="${kite}" th:class="${kite}" th:text="${kite}">

1.3 语法规则

  1. th:text 改变当前的元素里面的标签内容
  2. th : 任意的html属性,来替换原来的属性值,例如th:id="${kite},替换id的属性值
    在这里插入图片描述
  3. 表达式

***${…}***:获取变量值;OGNL;(使用最多的获取值的方式)

Simple expressions:(表达式语法)
    Variable Expressions: ${
   ...}:获取变量值;OGNL;
    		1)、获取对象的属性、调用方法
    		2)、使用内置的基本对象:
    			#ctx : the context object.
    			#vars: the context variables.
                #locale : the context locale.
                #request : (only in Web Contexts) the HttpServletRequest object.
                #response : (only in Web Contexts) the HttpServletResponse object.
                #session : (only in Web Contexts) the HttpSession ob
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值