您好,欢迎访问一九零五行业门户网

velocity第二个应用例子—访问对象

首先创建一个对象,提供构造方法
只需初始化一次即可。
//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());
模板
person.vm $person.id=$person.name ----- ${person.id},${person.name},${person.age}
以上就是velocity第二个应用例子—访问对象的内容。
其它类似信息

推荐信息