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>