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