Thymeleaf属性优先级

本文介绍Thymeleaf模板引擎中th:*属性的处理优先级,详细说明了从片段包含到片段移除的不同层级及其应用实例。

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

同计算机语言中各种操作符有优先级一样,类似的当同一个标签中有多个th:*属性时,Thymleaf在处理这些属性时也有优先级的问题。

<ul>
  <li th:each="item : ${items}" th:text="${item.description}">Item description here...</li>
</ul>

Thymleaf中定义的属性优先级,从上到下优先级越来越低

OrderFeatureAttributes
1Fragment inclusionth:include th:replace
2Fragment iterationth:each
3Conditional evaluationth:if th:unless th:switch th:case
4Local variable definitionth:object th:with
5General attribute modificationth:attr th:attrprepend th:attrappend
6Specific attribute modificationth:value th:href th:src …
7Text (tag body modification)th:text th:utext
8Fragment specificationth:fragment
9Fragment removalth:remove

因为不按书写顺序定义优先级,同一个标签中th:*属性书写顺序本身不会影响最终的执行结果,以下代码将和开头的代码有同样的输出。

<ul>
  <li th:text="${item.description}" th:each="item : ${items}">Item description here...</li>
</ul>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值