引入Thymeleaf依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
html里的动态text示例
先加上这个命名空间格式
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<hr/>
<p th:text="${name}"></p>
引入公共片段
被别人引入的header.html
<div th:fragment="header_common">这是声明公共片段</div>
去引入别人的
<div th:replace="header :: header_common"></div>
与th:replace相似的是th:insert
区别:使用th:insert,公共片段的标签和当前标签都会保留,而th:replace会将公共片段的标签全部覆盖当前标签
本文详细介绍了如何在Spring Boot项目中引入Thymeleaf依赖,并展示了如何使用Thymeleaf进行HTML文本的动态渲染,包括使用命名空间格式、动态文本插入、以及如何引入和使用公共片段,如header.html,通过th:replace和th:insert属性实现页面布局的复用。

556

被折叠的 条评论
为什么被折叠?



