Home>Article>Backend Development> Velocity’s second application example—accessing objects

Velocity’s second application example—accessing objects

黄舟
黄舟 Original
2017-01-17 10:46:45 1042browse

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)!


Statement:
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