網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
thymeleaf中th:include, th:insert, th:replace的區(qū)別
一、代碼和介紹
- footer.html
<footer th:fragment="copy">
需要copy的代碼...
</footer>
- 需要引用copy的頁(yè)面,有三種方式
- 【注意】這里的footer是頁(yè)面的名稱,不是標(biāo)簽的名稱
<body>
...其他代碼
<div th:insert="footer :: copy"></div>
<div th:replace="footer :: copy"></div>
<div th:include="footer :: copy"></div>
</body>
-
渲染后的效果
-
th:insert
- 相當(dāng)于把需要引入的內(nèi)容,標(biāo)簽+代碼一同引如到div內(nèi)部
<div> <footer th:fragment="copy"> 需要copy的代碼... </footer> </div>
-
th:replace
-
th:replace
是在div標(biāo)簽上寫的,渲染效果則是用footer把div替換掉
<footer th:fragment="copy"> 需要copy的代碼... </footer>
-
-
th:include
- 將footer標(biāo)簽體內(nèi)的內(nèi)容,放到div中進(jìn)行渲染,div中原先有的內(nèi)容也會(huì)被覆蓋掉
<div> <footer th:fragment="copy"> 需要copy的代碼... </footer> </div>
-
二、演示截圖
- 代碼截圖
- chrome瀏覽器中渲染后的結(jié)果
原文鏈接:https://blog.csdn.net/BlackBox_/article/details/122111384
相關(guān)推薦
- 2023-02-05 Python?面向?qū)ο缶幊淘斀鈅python
- 2022-12-11 瀏覽器控制臺(tái)報(bào)錯(cuò)Failed?to?load?module?script:解決方法_nginx
- 2023-04-27 解讀react的onClick自動(dòng)觸發(fā)等相關(guān)問(wèn)題_React
- 2022-06-17 C#關(guān)鍵字in、out、ref的作用與區(qū)別_C#教程
- 2022-10-13 Windows命令批處理的用法詳解_DOS/BAT
- 2022-10-03 github訪問(wèn)速度慢的問(wèn)題完美解決_相關(guān)技巧
- 2022-05-15 go?RWMutex的實(shí)現(xiàn)示例_Golang
- 2023-01-15 SqlServer?多種分頁(yè)方式?詳解(含簡(jiǎn)單速度測(cè)試)_MsSql
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支