迭代循环-Thymeleaf常见用法(四)

迭代

基本使用

th:each

th:each=“ prod : ${prods}”

${prods} 称为迭代表达式,prod称为迭代变量(单个量)

可迭代的值

**The java.util.List class isn’t the onlyvalue that can be used for iteration in Thymeleaf. There is a quite complete set of\
objects that are considered iterable by a th:each attribute:\
Any object implementing java.util.Iterable\
Any object implementing java.util.Enumeration .\
Any object implementing java.util.Iterator , whose values will be used as they are returned by the iterator, without\
the need to cache all values in memory.\
Any object implementing java.util.Map . When iterating maps, iter variables will be of class java.util.Map.Entry .\
Any array.\
Any other object will be treated as if it were a single-valued list containing the object itself.**

迭代状态量

索引:The current iteration index, starting with 0.This is the index property.

计数:The current iteration index, starting with 1 .This is the count property.

总量:The total amount of elements in the iterated variable.This is the size property.

当前:The iter variable for each iteration.This is the current property.

奇偶:Whether the current iteration is even or odd.These are the even/odd boolean properties.

第一个:Whether the current iteration is the first one.This is the first boolean property.

最后一个:Whether the current iteration is the last one.This is the last boolean property.

th:each=“ prod, iterStat : ${prods}”

上面的iterStat,就是状态变量,要使用它的状态参数,只需要使用 . 属性,例如使用索引就是 iterStat.index

懒加载

实现ILazyContextVariable,接口,可以实现懒加载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值