区别
th:insert 如同插入的字面意思,将指定的代码片段插入主标签内
th:replace 如同替换的字面意思,将主标签替换为指定的代码片段
th:include (3.0版本后已不推荐使用) 类似于th:insert, 不同的是在插入的时候不带代码片段的标签,只插入代码
例子展示
- 被插入的代码
<footer th:fragment="copy">
hello world
</footer>
- 三种方式使用
<div th:insert="footer :: copy"></div>
<div th:replace="footer :: copy"></div>
<div th:include="footer :: copy"></div>
- 插入后的真实代码
<div>
<footer>
hello world
</footer>
</div>
<footer>
hello world
</footer>
<div>
hello world
</div>
- 如果要跨页面显示的话格式如下
如果需要将main里面的一个页面放置到student文件夹里的页面
<div th:replace="~{main/main::top-select}"></div>