版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Java_Glory/article/details/89886423
1、抽取公共片段
<div th:fragment="copy">
© 2011 The Good Thymes Virtual Grocery
</div>
2、引入公共片段
<div th:insert="~{footer :: copy}"></div>
~{templatename::selector}:模板名::选择器
~{templatename::fragmentname}:模板名::片段名
3、默认效果:
insert的公共片段在div标签中
如果使用th:insert等属性进行引入,可以不用写~{}:
行内写法可以加上:[[~{}]];[(~{})];
4,三种引入公共片段的th属性:
th:insert:将公共片段整个插入到声明引入的元素中
th:replace:将声明引入的元素替换为公共片段
th:include:将被引入的片段的内容包含进这个标签中
例:
<footer th:fragment="copy">
© 2011 The Good Thymes Virtual Grocery
</footer>
①引入方式:
<div th:insert="footer :: copy"></div>
①效果:
<div>
<footer>
© 2011 The Good Thymes Virtual Grocery
</footer>
</div>
②引入方式:
<div th:replace="footer :: copy"></div>
②效果:
<footer>
© 2011 The Good Thymes Virtual Grocery
</footer>
③引入方式:
<div th:include="footer :: copy"></div>
③效果:
<div>
© 2011 The Good Thymes Virtual Grocery
</div>
更多内容参见:官方PDF文档