日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

thymeleaf中th:include, th:insert, th:replace的區(qū)別

作者:BlackBox_ 更新時(shí)間: 2022-01-07 編程語(yǔ)言

thymeleaf中th:include, th:insert, th:replace的區(qū)別

一、代碼和介紹

  1. footer.html
<footer th:fragment="copy">
	需要copy的代碼...
</footer>
  1. 需要引用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>
  1. 渲染后的效果

    1. th:insert

      • 相當(dāng)于把需要引入的內(nèi)容,標(biāo)簽+代碼一同引如到div內(nèi)部
      <div>
      	<footer th:fragment="copy">
      	需要copy的代碼...
      	</footer>
      </div>
      
    2. th:replace

      • th:replace是在div標(biāo)簽上寫的,渲染效果則是用footer把div替換掉
      <footer th:fragment="copy">
      	需要copy的代碼...
      </footer>
      
    3. th:include

      • 將footer標(biāo)簽體內(nèi)的內(nèi)容,放到div中進(jìn)行渲染,div中原先有的內(nèi)容也會(huì)被覆蓋掉
      <div>
      	<footer th:fragment="copy">
      	需要copy的代碼...
      	</footer>
      </div>
      

二、演示截圖

  1. 代碼截圖

在這里插入圖片描述

  1. chrome瀏覽器中渲染后的結(jié)果

在這里插入圖片描述

原文鏈接:https://blog.csdn.net/BlackBox_/article/details/122111384

欄目分類
最近更新