Velocity's second application example—accessing objects

黄舟
Release: 2023-03-04 21:26:01
Original
1110 people have browsed it

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

Template

person.vm

$person.id=$person.name



-----

${person.id},${person.name},${person.age}
Copy after login

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 (www.php.cn)!


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