//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 ========
以上就是的内容。