Thymeleaf引入公共片段方式

博客介绍了Thymeleaf引入公共片段的三种th属性,即th:insert将公共片段插入声明元素中,th:replace用公共片段替换声明元素,th:include将片段内容包含进标签。还提及引入语法,行内写法需加~{},并给出参考链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

引入公共片段

引入公共片段的th属性,包括三种方式

th:insert

将公共片段,整个插入到声明引入的元素中

th:replace

将声明引入的元素,替换为公共片段

th:include

将被引入的片段的内容,包含进这个标签中

抽取公共片段

1 <footer th:fragment="copy">
2 &copy; 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 &copy; 2011 The Good Thymes Virtual Grocery
 4 </footer>
 5 </div>
 6 
 7 <footer>
 8 &copy; 2011 The Good Thymes Virtual Grocery
 9 </footer>
10 
11 <div>
12 &copy; 2011 The Good Thymes Virtual Grocery
13 </div>

注意

引入语法~{} 
波浪线、花括号可以写,可以不写

但是,在行内写法中[[~{}]]、[(~{})] 
必须,加上~{}

 

参考:https://blog.youkuaiyun.com/nangeali/article/details/82215708

转载于:https://www.cnblogs.com/116970u/p/10574862.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值