当使用 th:fragment 时
公共模板中:
1 2 3 4 5 6 7
| <footer th:fragment="copy"> footer中的公共内容 </footer> <footer id="copysection"> footer中的公共内容 </footer>
|
使用公共模板的页面中:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <body>
. . .
<div th:insert="footer :: copy"></div>
<div th:replace="footer :: copy"></div>
<div th:include="footer :: copy"></div>
<div th:ins../rep../inc="footer :: #copysection"></div> <!-- 此处要使用#进行选择 -->
</body>
|
使用公共模板的页面的效果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <body>
. . .
<!-- th:insert="footer :: copy" --> <div> <footer> footer中的公共内容 </footer> </div>
<!-- th:replace="footer :: copy" --> <footer> footer中的公共内容 </footer>
<!-- th:include="footer :: copy" --> <div> footer中的公共内容 </div>
</body>
|
🔍 th:insert 相当于将公共模板连带公共标签插入新标签中,此过程保留新标签
🔍 th:replace 相当于用公共模板连带标签替换新标签,不保留新标签
🔍 th:include 相当于将公共模板标签中的内容插入新标签,不保留旧标签