抽取公共内容---thymeleaf

声明重复片段
<!--引用时要在名称id前加上 #
  <div th:instert="comon :: #commonheader"></div>
                     文件名     片段名称
 -->
<head id="commonheader">

<footer th:fragment="commonscript">
 &copy; 2011 The Good Thymes Virtual Grocery
</footer>
引用重复片段
<div th:instert="comon :: commonscript"></div>

<div th:replace="comon :: commonscript"></div>

<div th:include="comon :: commonscript"></div>

instert:在当前标签中加入重复片段中包含标签的文本内容

<div>
  <footer>
   &copy; 2011 The Good Thymes Virtual Grocery
  </footer>
</div>

replace:将当前标签替换为重复片段中包含标签的文本内容

 <footer>
   &copy; 2011 The Good Thymes Virtual Grocery
  </footer>

include:在当前标签中加入重复片段中不包含标签的文本内容

 <div>
   &copy; 2011 The Good Thymes Virtual Grocery
  </div>
posted @ 2021-08-21 16:25  潮哥啊边伦个  阅读(44)  评论(0)    收藏  举报