Home > Backend Development > PHP Tutorial > The fourth application example of velocity---Traversing Map collection

The fourth application example of velocity---Traversing Map collection

黄舟
Release: 2023-03-04 21:28:01
Original
2065 people have browsed it

velocityThe fourth application example---traversing the Map collection

//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());
Copy after login



template

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

The above is For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template