th:block 笔记
说明
时间赶的话可以直接看 2 中的粗体部分,和 3
1. 官方文档
https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#synthetic-thblock-tag
2. 使用说明
11.4. Synthetic
th:block
tag 合成的?人造的?
th:block
标签? 我觉得这里的意思应该是
th:block
是 Thymeleaf 提供的(块状)标签。
Thymeleaf’s only element processor (not an attribute) included in the Standard Dialects is
th:block
. Thymeleaf 的标准方言中包含的唯一的 Thymeleaf 元素处理器 (不是属性)。
th:block
is a mere attribute container that allows template developers to specify whichever attributes they want. Thymeleaf will execute these attributes and then simply make the block, but not its contents, disappear.
th:block
是一个属性容器,允许模板开发人员指定他们想要的属性。Thymeleaf 将执行这些属性,然后简单地使块消失,而不留下痕迹。 Thymeleaf 模板引擎在处理
th:block
的时候会删掉它本身,标签本身不显示,只显示内容,当没有从后端获取到内容时,就不显示
So it could be useful, for example, when creating iterated tables that require more than one
<tr>
for each element: 因此,在有些情况它可能有用。比如,当创建迭代表时,每个元素需要多个
<tr>
。 使用
th:block
和table
配合,可以批量获取到数据并组装成对应的前端页面显示,好处是如果没有获取到数据,则不会显示任何内容
<table> <th:block th:each="user : ${users}"> <tr> <td th:text="${user.login}">...</td> <td th:text<