首先我们要只他们怎么用,他们的用法都是一样的,{}中双冒号前是文件的路径,后面是文件中取的th:fragment的名字
<div th:include="~{/backstage/header.html::header}"></div>
<div>中间</div>
<div th:include="~{/backstage/footer.html::footer}"></div>
<div th:insert="footer :: copy"></div>
<div th:replace="footer :: copy"></div>
th:insert
- 相当于把需要引入的内容,标签+代码一同引如到div内部
th:replace
th:replace
是在div标签上写的,渲染效果则是把div替换掉,也就是说使用他之后
th:include(3.0版本以后基本就和th:insert一样了,所以主要掌握前面两种的区别即可)
- 将标签体内的内容,放到div中进行渲染,div中原先有的内容也会被覆盖掉
<div>
<footer>
hello world
</footer>
</div>
<footer>
hello world
</footer>