1. 程式人生 > >從零學習freemarker 3 IF語句的使用

從零學習freemarker 3 IF語句的使用

package freemarker;import java.io.File;import java.io.FileOutputStream;import java.io.OutputStreamWriter;import java.io.Writer;import java.util.HashMap;import java.util.Map;import freemarker.template.Configuration;import freemarker.template.Template;publicclass TestIf {private Configuration cfg;public
 Configuration getCfg() {return cfg;  }publicvoid init() throws Exception {    cfg = new Configuration();    cfg.setDirectoryForTemplateLoading(new File("bin/freemaker"));  }publicstaticvoid main(String[] args) throws Exception {    TestIf obj = new TestIf();    obj.init();    Map root = new HashMap();
    root.put("user""java2000.net");    Map latestProduct = new HashMap();    latestProduct.put("url""http://www.java2000.net");    latestProduct.put("name""Java世紀網");    root.put("latestProduct", latestProduct);    Template t = obj.getCfg().getTemplate("TestIf.ftl");    Writer out = new OutputStreamWriter(
new FileOutputStream("TestIf.html"), "GBK");    t.process(root, out);    System.out.println("Successfull................");  }}