迭代
基本使用
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,接口,可以实现懒加载