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>

 

 

 

  

 

posted @ 2020-11-15 21:31  Mr_sven  阅读(763)  评论(0编辑  收藏  举报