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); }