thymeleaf里insert、replace、include之间有些什么区别?
其实这3者都很相像。都是引入片段。区分起来的话:
th:insert 插入片段,保留自身标记
th:replace 插入片段,替换了自身标记
th:include 插入片段的内容,去掉片段外层标记,同时保留自身标记
比如有这么个标记
<footer th:fragment="copy">
© 2011 The Good Thymes Virtual Grocery
</footer>
- 1
- 2
- 3
然后分别用insert、replace、include来引用:
<body>
<div th:insert="footer :: copy"></div>
<div th:replace="footer :: copy"></div>
<div th:include="footer :: copy"></div>
</body>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
运行结果:
<body>
<div>
<footer>
© 2011 The Good Thymes Virtual Grocery
</footer>
</div>
<footer>
© 2011 The Good Thymes Virtual Grocery
</footer>
<div>
© 2011 The Good Thymes Virtual Grocery
</div>
</body>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17





![战神引擎传奇手游【1.76盛战传奇免授权版[摸摸登陆器]】最新整理Win系复古服务端+安卓苹果双端+GM授权物品后台+详细搭建教程](https://cdn.jxasp.com:9143/image/20251106/1B4E8594B3BEB90E8601D63A8A39CB0B.jpg)













