当前位置: 代码迷 >> Web前端 >> freemarker list (长度,遍历,上标,嵌套,排序)
  详细解决方案

freemarker list (长度,遍历,上标,嵌套,排序)

热度:1351   发布时间:2013-01-26 13:47:01.0
freemarker list (长度,遍历,下标,嵌套,排序)
1. freemarker获取list的size :

Java
ArrayList<String> list = new ArrayList<String>();

Freemaker
${list?size}


2. list的遍历:

<#list animals as being>
    <tr>
        <td>${being.name}${being.price}<td>
    </tr>
</#list>


3.list遍历中的下标序号:

_index是list的一个属性
<#list list as a>
     ${a_index}
</#list> 


4. list的嵌套:
<#list jsskList as jsskVO>
   <#list kcList as kcVO>
           <#if kcVO.kch=jsskVO.kch> (kcVO里有编号和名称,而jsskVO里只有编号)
                  ${kcVO.kcm} 
           </#if>
   </#list>
</#list>


5. list排序:
      升序 .sort_by()
<#list list?sort_by("字段") as x>
</#list>


     降序 .sort_by()?reverse
<#list list?sort_by("字段")?reverse as x> 
</#list>
  相关解决方案