PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

velocity第四个应用例子---遍历Map集合

黄舟
黄舟 原创
2017-01-17 10:51:19 1784浏览

velocity第四个应用例子---遍历map集合

//2 Create a Context object
VelocityContext context = newVelocityContext();
//3 Add you data objects to this context
Map<String,String> map = newHashMap<String,String>();
map.put("key1","value1");
map.put("key2","value2");
map.put("key3","value3");
map.put("key4","value4");
context.put("map", map);
//4 Choose a template
Template template =Velocity.getTemplate("map.vm");
//5 Merge the template and you data toproduce the output
StringWriter sw = new StringWriter();
template.merge(context, sw);
sw.flush();
System.out.println(sw.toString());



模板

#foreach($keyin $map.keySet())
$key:$map.get($key)
#end
========

以上就是的内容,更多相关内容请关注PHP中文网(www.php.cn)!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。