Thymeleaf教程(10) - 属性的优先级列表
发布于 2022-05-01    449 次阅读
当你在一个tag里面定义多个属性后。优先级就比较重要了。 <ul> <li th:each="item : ${items}" th:text="${item.description}">Item description here...</li> </ul> 上述代码必须先执行each,再执行text,否则就会出错。为了保证上述优先级,Thymeleaf给自己的属性都定义了一个顺序。 Thymel...

当你在一个tag里面定义多个属性后。优先级就比较重要了。

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

上述代码必须先执行each,再执行text,否则就会出错。为了保证上述优先级,Thymeleaf给自己的属性都定义了一个顺序。

Thymeleaf的优先级定义是通过数字标记的升序来定义,这个顺序是:

顺序 功能 属性
1 模块包含 th:include,th:replace
2 模块循环 th:each
3 条件判断 th:if,th:unless,th:switch,th:case
4 局部变量 th:object,th:with
5 通用属性修改 th:attr,th:attrprepend,th:attrappend
6 特殊属性修改 th:value,th:href,th:src…
7 文本显示 th:text,th:utext
8 模块定义 th:fragment
9 模块移除 th:remove

版权说明 : 本文为转载文章, 版权为原作者所有

原文标题 : Thymeleaf教程 (十) 属性的优先级列表

原文连接 : https://blog.csdn.net/mygzs/article/details/52537470