Freemarker将列表长度分配给局部变量

cuh*_*cuh 20 freemarker exception variable-assignment

以下freemarker代码会导致异常

<#assign i= it.getList().size()>
<#list it.getList() as elem>
    <#if i==1>
    <li>${elem.name}</li>
    <#else>
    <li class="marked">${elem.name}</li>
    </#if>
    <#assign i = i-1>
</#list>
Run Code Online (Sandbox Code Playgroud)

抛出以下异常:

期待哈希.it.getList()被评估为freemarker.template.SimpleSequence

谁知道为什么?如何将列表的长度分配给我的变量i

cuh*_*cuh 38

I figured out, that it did not understood the syntax for the size built-in. The right syntax for assigning the size of a list to a local variable is

<#assign i = it.getList()?size>
Run Code Online (Sandbox Code Playgroud)