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

 

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

  • th:insert   :保留自己的主标签,保留th:fragment的主标签。

  • th:replace :不要自己的主标签,保留th:fragment的主标签。

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


[html] view plain copy
  1. <span style="font-family:SimHei;font-size:18px;">需要替换的片段内容:  
  2. <footer th:fragment="copy">  
  3.    <script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}">script>  
  4. footer>  
  5.   
  6. 导入片段:  
  7.   
  8.   <div th:insert="footer :: copy">div>  
  9.   
  10.   <div th:replace="footer :: copy">div>  
  11.   
  12.   <div th:include="footer :: copy">div>  
  13.     
  14.   
  15. 结果为:  
  16.   
  17. <div>  
  18.     <footer>  
  19.        <script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}">script>  
  20.     footer>    
  21. div>    
  22.   
  23. <footer>  
  24.   <script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}">script>  
  25. footer>    
  26.   
  27. <div>  
  28.   <script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}">script>  
  29. div>    
  30.   
  31. span>  




转载地址:http://blog.csdn.net/austral/article/details/73802396



你可能感兴趣的:(前端,thymeleaf)