public static void main(String[] args) throws Exception {
        //得到模板
        Configuration cfg=new Configuration(Configuration.VERSION_2_3_25);
        cfg.setDirectoryForTemplateLoading(new File("src/ftl"));
        Template template=cfg.getTemplate("basic.ftl");
        //准备数据
        Map<Object,Object> date=new HashMap<Object,Object>();
        date.put("name", "夏末");
        User user=new User();
        user.setAge(24);
        user.setName("xiamo");
        date.put("user", user);
        //确定输出流
        Writer writer=new FileWriter(new File("src/ftl/basic.html"));
        writer=new OutputStreamWriter(System.out);
        //模板和数据结合
        template.process(date, writer);
    }

 

 posted on 2017-02-21 17:19  夏末秋萍  阅读(304)  评论(0编辑  收藏  举报