freemarker的list指令遍历一个list集合中的每一个元素,例如:

<#list userLists as user>
    ${user.name}
    ...
</#list>

其实list指令还隐含了两个变量,

1、item_index 该变量将返回元素在集合里的索引值,从0开始计数;

2、item_has_next 该变量是boolean型,false表明该元素是Sequences里的最后一个元素。

上述例子中如果需要把序号打印出来,使用${user_index}即可,同时如果想判断是否是最后一个元素,使用 user_has_next就行了。

相关文章:

  • 2022-02-08
  • 2022-01-17
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
  • 2021-05-15
  • 2021-09-11
  • 2021-06-11
猜你喜欢
  • 2021-12-01
  • 2021-08-24
  • 2022-12-23
  • 2021-10-03
  • 2022-01-04
  • 2021-06-07
相关资源
相似解决方案