首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >关于thymeleaf th:replace th:include th:insert 的区别

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

作者头像
ydymz
发布于 2018-09-10 16:03:20
发布于 2018-09-10 16:03:20
1.7K0
举报
文章被收录于专栏:lgp20151222lgp20151222

关于thymeleaf th:replace th:include th:insert 的区别     th:insert   :保留自己的主标签,保留th:fragment的主标签。     th:replace :不要自己的主标签,保留th:fragment的主标签。     th:include :保留自己的主标签,不要th:fragment的主标签。(官方3.0后不推荐)

例子

代码语言:javascript
复制
    <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>  

 依次导入

代码语言:javascript
复制
      <div th:insert="footer :: copy"></div>  
      
      <div th:replace="footer :: copy"></div>  
     
      <div th:include="footer :: copy"></div>  

结果

代码语言:javascript
复制
    <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>    
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-02-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档