Thymeleaf模板布局

⒈定义片段

  1.使用th:fragment   

1     <div th:fragment="copy">
2         &copy; 2019 <a href="http://www.coreqi.cn">Coreqi</a>
3     </div>

  2.不使用th:fragment 

1     <div id="copy-section">
2         &copy; 2019 <a href="http://www.coreqi.cn">Coreqi</a>
3     </div>

⒉引用片段

  1.引用使用th:fragment的片段

1     <div th:insert="~{footer :: copy}"></div>

  2.引用不使用th:fragment的片段

1     <div th:insert="~{footer :: #copy-section}"></div>

⒊引用模板使用的th:insert、th:replace、th:include三者之间的区别

  • th:insert  将简单地插入指定的片段作为正文的主标签
  • th:replace      用指定实际片段来替换其主标签
  • th:include        类似于th:insert,但不是插入片段,而是只插入此片段的内容(3.x版本后不再推荐使用)

 

posted @ 2019-03-14 20:34  SpringCore  阅读(572)  评论(0编辑  收藏  举报