0
点赞
收藏
分享

微信扫一扫

Thmeleaf公共部分抽取以及th:insert th:replace th:include 区别

读思意行 2022-10-09 阅读 165


目录

 

​​引入语法​​

​​关于thymeleaf th:replace th:include th:insert 的区别​​

引入语法

Thmeleaf公共部分抽取以及th:insert th:replace th:include 区别_javascript

关于thymeleaf th:replace th:include th:insert 的区别

  • th:insert   :保留自己的主标签,保留th:fragment的主标签。
  • ​th:replace​​ :不要自己的主标签,保留th:fragment的主标签。
  • ​th:include​​ :保留自己的主标签,不要th:fragment的主标签。(官方3.0后不推荐)

需要替换的片段内容:
<footer th:fragment="copy">
<script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}"></script>
</footer>

导入片段:

<div th:insert="footer :: copy"></div>

<div th:replace="footer :: copy"></div>

<div th:include="footer :: copy"></div>


结果为:

<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>

 

举报

相关推荐

0 条评论