首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Velocity 遍历Map部类,List类型

2012-09-09 
Velocity 遍历Map类型,List类型?MapString,String paramValuesnew HashMapString, String()******

Velocity 遍历Map类型,List类型

    ?Velocity 遍历Map部类,List类型Map<String,String> paramValues=new HashMap<String, String>();****** 中间赋值操作省略了***data.put("paramValues", paramValues);//传值给velocity


    2.前台velocity模板文件中取出这个map的key和value

      ?Velocity 遍历Map部类,List类型#foreach($param in ${paramValues.keySet()})<tr><th>$param</th><td>${paramValues.get($param)}</td></tr>#end




      二.遍历List类型

      1.先看后台java代码

        ?Velocity 遍历Map部类,List类型List<Saler> salerList=new ArrayList<Saler>();******中间赋值操作省略了***data.put("salerList", salerList);//传值给velocity



        2.再看velocity模版中代码

          ?Velocity 遍历Map部类,List类型#foreach($sal in ${salerList})$sal.name#end



          ps:这里补充说明一下,velocity中虽然可以用对象,就像这个list泛型中的Saler,但是要求这个Saler必须是public class Saler{xxxxx}的,也就是说不能为内部类..不能是写在别的类里面的 class Saler{xxxxx},而且这个类的成员变量要有get,set方法,不然就取不出来..具体为啥..不清楚..等待有经验的哥们解释一下~~

热点排行