關於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后不推薦)

例子

    <span style="font-family:SimHei;font-size:18px;">需要替換的片段內容:  

//copy代碼片 <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>    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM