關(guān)于thymeleaf th:replace th:include th:insert 的區(qū)別:
- th:insert :保留自己的主標(biāo)簽,保留th:fragment的主標(biāo)簽蟆融。
- th:replace :不要自己的主標(biāo)簽,保留th:fragment的主標(biāo)簽。
- th:include :保留自己的主標(biāo)簽番官,不要th:fragment的主標(biāo)簽位衩。(官方3.0后不推薦)
<span style="font-family:SimHei;font-size:18px;">需要替換的片段內(nèi)容:
<footer th:fragment="copy">
<script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}"></script>
</footer>
導(dǎo)入片段:
<div th:insert="footer :: copy"></div>
<div th:replace="footer :: copy"></div>
<div th:include="footer :: copy"></div>
結(jié)果為:
<div>
<footer>
<script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}"></script>
</footer>
</div>
<footer>
<script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}"></script>
</footer>
<div>
<script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}"></script>
</div>
</span>