直接循环集合:

<#list userList! as user> 
<td>${user.userName}</td>

<#if user_index = 0><#break></#if> 使用<#break>跳出循环,是"=", 不是"=="
</#list>

获取循环的下标:user_index

判断是否存在下一个对象(boolean类型):user_has_next



用数字来循环集合:

<#list 0..userList?size-1 as i>
<td>${(userList[i].userName)!}</td>
</#list>

计算集合长度:userList?size



截取子集合

userList[3..5] //返回集合中的第4-6个元素



获取list长度

${userList?size}

而需要判断长度时,单纯使用

<#if userList?size>0 >
</#if>

是不可行的,会报错freemarker.core.NonBooleanException,意指不是boolean类型。正确的写法是加一个括号,或者使用gt代替>符号。

<#if (userList?size>0) >
</#if>


<#if userList?size gt 0 >
</#if>



判断是否存在某元素;求第一次出现的索引

<#assign userList = ["张三",  "李四", "王五", "赵六"]> 

${userList?seq_contains("赵六")?string("yes", "no")} // 显示: yes
${userList?seq_index_of("王五")} // 显示: 2