【SpringMVC笔记12】SpringMVC集成Thymeleaf模板引擎

本文详细介绍了SpringMVC如何集成Thymeleaf模板引擎,包括引入依赖、配置视图解析器、创建HTML页面、编写Controller以及Thymeleaf的常用标签和表达式,如th:text、th:if、th:each等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这篇文章,主要介绍SpringMVC框架如何集成Thymeleaf模板引擎。

目录

一、SpringMVC集成Thymeleaf

1.1、引入Thymeleaf依赖

1.2、配置视图解析器

1.3、创建html页面

1.4、创建Controller控制器

1.5、运行测试

二、Thymeleaf模板引擎使用

2.1、常见标签

(1)th:text设置文本内容

(2)th:value设置表单值

(3)th:checked单选框是否选中

(4)th:selected下拉框是否选中

(5)th:src图片路径

2.2、链接表达式

2.3、th:if判断语句

2.4、th:switch判断语句

2.5、th:each循环

2.6、案例

(1)HTML页面

(2)Controller控制器


一、SpringMVC集成Thymeleaf

1.1、引入Thymeleaf依赖

SpringMVC框架中使用Thymeleaf模板引擎,需要引入thymeleaf的jar包依赖,以及thymeleaf和spring的适配依赖。

<!-- 引入 thymeleaf 依赖 -->
<!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf -->
<dependency>
  <groupId>org.thymeleaf</groupId>
  <artifactId>thymeleaf</artifactId>
  <version>3.0.11.RELEASE</version>
</dependency>
<!-- 引入 thymeleaf 和 spring5 的支持 -->
<!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring5 --&
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mr.小朱同学

随心赞赏,助力前行

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值