fragment介绍
fragment类似于JSP的tag,在html中文件中,可以将多个地方出现的元素块用fragment包起来使用。
fragment使用
定义fragment
所有的fragment可以写在一个文件里面,也可以单独存在,例如:新建index.html
<div th:fragment="copy"> the content of footer </div>
fragment的引用
- th:insert:保留自己的主标签,保留th:fragment的主标签。
- th:replace:不要自己的主标签,保留th:fragment的主标签。
- 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>