The second application example of velocity-sample code for accessing objects. you can refer to the following section to create an object and provide a constructor.
You only need to initialize it once.
// 2 Create a Context objectVelocityContext context = newVelocityContext (); // 3 Add you data objcts to this contextcontext. put ("person", newPerson (1, "Xiaozhang", 23); // 4 Choose a templateTemplate template = Velocity. getTemplate ("person. vm "); StringWriter sw = new StringWriter (); // 5 Merge the template and you data toproduce the outputtemplate. 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 information, see PHP Chinese network (www.php1.cn )!