关于freemarker里面的hashmap使用问题

The Example is given:
        Map testMap = new HashMap();
        testMap.put("sh", "shanghai ");
        testMap.put("bt", "北京 ");
   如果Map里面的Key是Object(String,Integer,etc)就有问题 。因为freemarker里面没有TypeConverter机制,现在只能是字符串。
freemarker显示hashmap存取的格式如下

<#list testMap?keys as testKey>
       < option value="${testKey}" >
              ${testMap[testKey]}

     </option>
<
/#list>

------------------------------------个人使用经验:以上的说法是错误的

当Map里面的key 是Object(String,Integer,etc)等要通过以下的方式来得到
<#list testMap?keys as testKey>
       < option value="${testKey}" >

              ${testMap.get(testKey)}

     </option>
<
/#list>

或者使用:

<#list testMap.keySet() as testKey>
       < option value="${testKey}" >

        ${testMap.get(testKey)}

     </option>
<
/#list>

--------切记在webwork自带的freemarker中对Map中Key的定义为String类型(如果你想用${Map[key]}这样取值的话;如果用${Map.get(key}这样取值就可以用其他类型,如Map<Long,Object>),更高片本是否可以用其他类型本人未曾验证

posted @ 2010-02-24 17:30  蟋蟀的草坪  阅读(5076)  评论(0编辑  收藏  举报