一文教你学会使用 th:block

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:blocktable 配合,可以批量获取到数据并组装成对应的前端页面显示,好处是如果没有获取到数据,则不会显示任何内容

<table>
<th:block th:each="user : ${users}">
 <tr>
     <td th:text="${user.login}">...</td>
     <td th:text<
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Quantum_Wu

一起加油呀ヾ(◍°∇°◍)ノ゙

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值