引入公共片段
引入公共片段的th屬性,包括三種方式
th:insert
將公共片段,整個插入到聲明引入的元素中
th:replace
將聲明引入的元素,替換為公共片段
th:include
將被引入的片段的內容,包含進這個標簽中
抽取公共片段
1 <footer th:fragment="copy"> 2 © 2011 The Good Thymes Virtual Grocery 3 </footer>
引入方式
1 <div th:insert="footer :: copy"></div> 2 <div th:replace="footer :: copy"></div> 3 <div th:include="footer :: copy"></div>
頁面效果
1 <div> 2 <footer> 3 © 2011 The Good Thymes Virtual Grocery 4 </footer> 5 </div> 6 7 <footer> 8 © 2011 The Good Thymes Virtual Grocery 9 </footer> 10 11 <div> 12 © 2011 The Good Thymes Virtual Grocery 13 </div>
注意
引入語法~{}
波浪線、花括號可以寫,可以不寫
但是,在行內寫法中[[~{}]]、[(~{})]
必須,加上~{}
參考:https://blog.csdn.net/nangeali/article/details/82215708