怎么把velocity模版生成html

2025-03-13 20:58:58
推荐回答(1个)
回答1:

Velocity.init();
VelocityContext context = new VelocityContext();
context.put("name", "yy");
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
Template template = Velocity.getTemplate("VelocityTest1.vm");
template.merge(context, writer);
writer.flush();
writer.close();
把System.out换成文件输出流,就生成html了。