六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 21|回复: 0

从零学习freemarker(5)Include的使用

[复制链接]

升级  10.8%

386

主题

386

主题

386

主题

探花

Rank: 6Rank: 6

积分
1216
 楼主| 发表于 2013-2-7 16:48:34 | 显示全部楼层 |阅读模式
http://www.java2000.net/p7861
Include的使用

     代码


<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................");
  •   }
  • }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表