从零学习freemarker(5)Include的使用
http://www.java2000.net/p7861Include的使用
代码
<div class="highlighter">
[*]package freemarker;
[*]<span />
[*]<span />import java.io.File;
[*]<span />import java.io.FileOutputStream;
[*]<span />import java.io.OutputStreamWriter;
[*]<span />import java.io.Writer;
[*]<span />import java.util.HashMap;
[*]<span />import java.util.Map;
[*]<span />import freemarker.template.Configuration;
[*]<span />import freemarker.template.Template;
[*]<span />
[*]<span />public class TestInclude {
[*] private Configuration cfg;
[*]<span />
[*] public Configuration getCfg() {
[*] return cfg;
[*] }
[*]<span />
[*] public void init() throws Exception {
[*] cfg = new Configuration();
[*] cfg.setDirectoryForTemplateLoading(new File("bin/freemaker"));
[*] }
[*]<span />
[*] public static void main(String[] args) throws Exception {
[*] TestInclude obj = new TestInclude();
[*] obj.init();
[*] Map root = new HashMap();
[*] Template t = obj.getCfg().getTemplate("TestInclude.ftl");
[*] Writer out = new OutputStreamWriter(new FileOutputStream("TestInclude.html"), "GBK");
[*] t.process(root, out);
[*] System.out.println("Successfull................");
[*] }
[*]}
页:
[1]