public class Test {
public static void main(String[] args) throws Exception {
Zxczf zxczf = new Zxczf();
zxczf.setAge("18");
VelocityContext ctx = new VelocityContext();
ctx.put("zxczf", zxczf);
Velocity.init();
FileWriter fw = new FileWriter("result.txt");
Template template = Velocity.getTemplate("test.vm","gb2312");
template.merge(ctx,fw);
fw.close();
}
}
class Zxczf {
private String age;
public void setAge(String age) {
this.age = age;
}
public String getAge() {
return age;
}
public String toString() {
return getAge();
}
}
<p>
|