Home>Article>Backend Development> Velocity’s second application example—accessing objects
First create an object and provide a constructor method
It only needs to be initialized once.
//2 Create a Context object VelocityContext context = newVelocityContext(); //3 Add you data objcts to this context context.put("person", newPerson(1,"小张",23)); //4 Choose a template Template template =Velocity.getTemplate("person.vm"); StringWriter sw = new StringWriter(); //5 Merge the template and you data toproduce the output template.merge(context, sw); sw.flush(); System.out.println(sw.toString());
Template
person.vm $person.id=$person.name ----- ${person.id},${person.name},${person.age}
The above is the second application example of velocity - the content of the access object. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!