springboot学习记录之 thymeleaf使用模板

本文记录了SpringBoot项目中整合Thymeleaf时遇到的问题及解决方案,重点在于如何使用Thymeleaf的`layout:fragment`特性。博主通过引入特定依赖解决无法使用的问题,并介绍了`th:insert`、`th:replace`、`th:include`三个标签的区别。通过创建`footer.html`、`left.html`和`layout.html`来构建基础模板,`th:insert`保留主标签,`th:replace`替换主标签,`th:include`不保留th:fragment主标签。在实际页面如`login.html`中,使用`layout:decorator`指定模板。
摘要由CSDN通过智能技术生成

开头奉上官方文档(http://www.thymeleaf.org/doc/articles/layouts.html)!

博主在整合前台页面整体布局的时候发现 layout:fragment 使用不了,查了一个多小时资料,才发现要引入一个包,下面奉上maven引入(建议在整合thymeleaf的时候顺便一起把这个依赖下载下来!!!!):

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> <!-- thymeleaf依赖-->
<dependency>
   <groupId>nz.net.ultraq.thymeleaf</groupId>
   <artifactId>thymeleaf-layout-dialect</artifactId>
   <version>2.2.1</version>  <!-- dialect依赖-->
</dependency>

下面开始创建模板(建立如下文件):

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值