FreeMarker 遍历list

FreeMarker:

记录一点数据输出结构

(root)
|
+- string
|
+- list{string,map}
|
+- map

  // Build the data-model
    	
     
     List<Object> list = new ArrayList<Object>();
     list.add("red");
     list.add("green");
     list.add("blue");
     SimpleHash mapColor = new SimpleHash();
     mapColor.put("c1", "red");
     mapColor.put("c2", "green");
     mapColor.put("c3", "blue");
     list.add(mapColor);
     
//     将会使用default wrapper
     SimpleHash root = new SimpleHash();
    
     root.put("theList", list);
    
     

 FTL 文件. 怎么遍历list中的map

***************************************************************<br>
+- theList<br>
 <#list theList as item>
| |<br>

****************第4个值放的map***********************************************<br>
 <#if item_index =3> <#assign keys = item?keys> <#list keys as key> ||<br> +- ${key} = ${item[key]}<br> </#list> <#else> +- ${item_index + 1}. ${item}<br> </#if>


</#list>
***************************************************************<br>

 output:

+- theList
| |
+- 1. red
| |
+- 2. green
| |
+- 3. blue
| |
||
+- c1 = red
||
+- c2 = green
||
+- c3 = blue

 

 

 参考,

http://www.iteye.com/topic/165112

附件: ―Programmer's Guide

你可能感兴趣的:(freemarker)