关键词搜索

源码搜索 ×
×

thymeleaf里insert、replace、include的区别

发布2019-12-19浏览1133次

详情内容

thymeleaf里insert、replace、include之间有些什么区别?

其实这3者都很相像。都是引入片段。区分起来的话:

th:insert 插入片段,保留自身标记

th:replace 插入片段,替换了自身标记

th:include 插入片段的内容,去掉片段外层标记,同时保留自身标记

比如有这么个标记

<footer th:fragment="copy">
  &copy; 2011 The Good Thymes Virtual Grocery
</footer>
  • 1
  • 2
  • 3

然后分别用insert、replace、include来引用:

<body>

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

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

  <div th:include="footer :: copy"></div>
  
</body>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

运行结果:

<body>

  <div>
    <footer>
      &copy; 2011 The Good Thymes Virtual Grocery
    </footer>
  </div>

  <footer>
    &copy; 2011 The Good Thymes Virtual Grocery
  </footer>

  <div>
    &copy; 2011 The Good Thymes Virtual Grocery
  </div>
  
</body>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载