这次我们来学习属性优先级。
当Thymeleaf在同一标签中遇到了至少两个属性时,需要按顺序执行它们:
<ul>
<li th:each="item : ${items}" th:text="${item.description}">Item description here...</li>
</ul>
th:each 属性需要在 th:text 属性之前执行,否则会出错。
Thymeleaf 通过建立数字优先级机制来保证我们得到想要的结果:(数字越小优先级越高)
Order | Feature | Attributes |
---|---|---|
1 | Fragment inclusion | th:insert/th:replace |
2 | Fragment iteration | th:each |
3 | Conditional evaluation | th:if/th:unless/th:switch/th:case |
4 | Local variable definitiont | th:object/th:with |
5 | General attribute modification | th:attr/th:attrprepend/th:attrappend |
6 | Specific attribute modification | th:value/th:href/th:src/... |
7 | Text (tag body modification) | th:text/th:utext |
8 | Fragment specification | th:fragment |
9 | Fragment removal | th:remove |
<ul>
<li th:text="${item.description}" th:each="item : ${items}">Item description here...</li>
</ul>
— 【参考资料 —— Thymeleaf文档20181029 - 29 October 2018】
已同步更新至个人博客:田超杰的个人网站-一个传播计算机知识和人生哲理的博客