声明公共代码片段
通过th:fragment
<div th:fragment="header_common">
<p>这是fragment公共片段</p>
</div>
通过id声明代码片段
<div id="header_common_id">
<p>这是id公共片段</p>
</div>
替换/插入
使用th:replace 通过th:fragment
<div th:replace="header :: header_common"></div>
使用th:replace 通过id
<div th:replace="header :: #header_common_id"></div>
使用th:insert 通过id
<h2 th:insert="header :: #header_common_id"></h2>
th:replace与th:insert区别
th:insert 和 th:replace都可以引入片段
两者的区别在于:
th:insert: 保留引入时使用的标签
th:replace:不保留引入时使用的标签,直接覆盖当前引用的标签