初识springboot 引入thymeleaf

因为springboot不支持jsp

使用模板引擎

写一个页面模板,和数据交给模板,生成一个页面。

推荐thymeleaf

语法简单功能强大,

1.引入thymeleaf

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

修改版本:

<properties>
    <java.version>1.8</java.version>
    <thymeleaf-spring5.version>3.0.9.RELEASE</thymeleaf-spring5.version>
    <thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
</properties>

2.使用语法:

按照自动配置规则来使用

只要我们把html页面放在templates里,就能自动渲染了,

 

在html文件中使用thymeleaf调用

首先导入thyme leaf提示

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

使用thymeleaf的语法

 th:text="":将div中文本内容设置为指定内容

语法规则:

th:任意html属性,就可以直接在后台之类的取值

片段包含:

th:insert 

th:replace

遍历:

th:each

条件判断:th:if

th:switch

th:unless

th:case

变量声明

th:object

th:with

属性修改

th:attr

th:attrprepend

th:attrappend

修改指定属性:

th:value

th:href

th:src

修改标签体内容

th:text

th:utext  不转义特殊字符

声明片段

th:fragmen

移除

th:remove

2.表达式

${}获取变量值,获取对象的属性,调用方法,使用内置基本对象,内置的工具对象。

*{}选择表达式和${}差不多但是有补充,

#{}国际化内容

@{}定义url链接的

~{}片段引用的表达式

 

<hr/>
    <div th:text="${he}"></div>
    <div th:utext="${he}"></div>
<hr/>
    <h4 th:text="${user}" th:each="user:${users}"}></h4>//users的值赋给user了然后显示
<hr/>
<h4>
    <span th:each="user:${users}">[[${user}]]</span>//[[]]这个直接代表th:text
</h4>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值