thymeleaf中的fragment页面分离使用


fragment介绍

fragment类似于JSP的tag,在html中文件中,可以将多个地方出现的元素块用fragment包起来使用。

fragment使用

定义fragment

所有的fragment可以写在一个文件里面,也可以单独存在,例如:新建index.html

<div th:fragment="copy">  
   the content of footer 
</div>

  

fragment的引用

  1. th:insert:保留自己的主标签,保留th:fragment的主标签。
  2. th:replace:不要自己的主标签,保留th:fragment的主标签。
  3. th:include:保留自己的主标签,不要th:fragment的主标签。(官方3.0后不推荐)
导入片段:
<div th:insert="index :: copy"></div>  
<div th:insert="~{index::copy}"></div>
<div th:replace="index :: copy"></div> <div th:include="index :: copy"></div>

 

 

 

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM