Velocity简单使用

public static void main(String[] args) throws Throwable {
String vmPath="D:\\SVN_Work\\MyERP_Core_Main\\MyERP_Core\\trunk\\trunk_1_4_1\\etc\\";
Properties p = new Properties();
p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, vmPath);
p.setProperty(Velocity.ENCODING_DEFAULT, "UTF-8");
p.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
p.setProperty(Velocity.OUTPUT_ENCODING, "UTF-8");
VelocityEngine engine=new VelocityEngine(p);

String tempName ="sunyh.vm";
Template template=engine.getTemplate(tempName);


VelocityContext context=new VelocityContext();

context.put("Name", "sunyh");
context.put("Age", 80);
context.put("Job", "yyyyyy");

Writer writer = new StringWriter();
template.merge(context, writer);
writer.flush();
System.out.println(writer.toString());
}

你可能感兴趣的:(velocity)