Velocity 遍历Map部类,List类型
Velocity 遍历Map类型,List类型?MapString,String paramValuesnew HashMapString, String()******
Velocity 遍历Map类型,List类型
?Map<String,String> paramValues=new HashMap<String, String>();****** 中间赋值操作省略了***data.put("paramValues", paramValues);//传值给velocity
2.前台velocity模板文件中取出这个map的key和value
?#foreach($param in ${paramValues.keySet()})<tr><th>$param</th><td>${paramValues.get($param)}</td></tr>#end
二.遍历List类型
1.先看后台java代码
?List<Saler> salerList=new ArrayList<Saler>();******中间赋值操作省略了***data.put("salerList", salerList);//传值给velocity
2.再看velocity模版中代码
?#foreach($sal in ${salerList})$sal.name#end
ps:这里补充说明一下,velocity中虽然可以用对象,就像这个list泛型中的Saler,但是要求这个Saler必须是public class Saler{xxxxx}的,也就是说不能为内部类..不能是写在别的类里面的 class Saler{xxxxx},而且这个类的成员变量要有get,set方法,不然就取不出来..具体为啥..不清楚..等待有经验的哥们解释一下~~