FreeMarkerUtl
/**
* @title FreeMarkerUtl
* @description 模板文件工具类
* @author maohuidong
* @date 2017-07-05
*/
public class FreeMarkerUtl {
/**
* @function genHtmlPage
* @param templatePath:模板路径 tempalteFile:模板文件名称 root:模板文件需要渲染的数据 genFilePath:生成的文件路径和名称
* @description 用户提交问卷
* @return (无)
* @throws Exception
* @author maohuidong
* @date 2017-07-05
*/
public static Boolean genHtmlPage(String templatePath,String tempalteFile,Map<Object, Object> root,String genFilePath){
try {
Configuration configuration = new Configuration();
//模板文件的路径
configuration.setDirectoryForTemplateLoading(new File(templatePath));
//字符集
configuration.setDefaultEncoding("utf-8");
//获取模板
Template template = configuration.getTemplate(tempalteFile, "utf-8");
//创建writer对象
File file = new File(genFilePath);
Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"utf-8"));
template.process(root, writer);
writer.flush();
writer.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return false;
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (TemplateException e) {
e.printStackTrace();
return false;
}
return true;
}
}
FreeMarkerUtl的更多相关文章
随机推荐
- TFTP error: 'Only absolute filenames allowed' (2)
hisilicon # tftp 0x82000000 u-boot-hi3518ev200.bin Hisilicon ETH net controler MAC: ----- eth0 : phy ...
- Oracle DataBase单实例使用ASM案例(1)--ASM基本概念
版权声明:本文为博主原创文章,未经博主允许不得转载. Oracle DataBase单实例使用ASM案例(1)--ASM基本概念 系统环境: 操作系统:RH EL5-64 Oracle 软件: Ora ...
- hashcode 知识点
java中常用的哈希码的算法. Object类的hashCode.返回对象的内存地址经过处理后的结构,由于每个对象的内存地址都不一样,所以哈希码也不一样. String类的hashCode.根据Str ...
- POJ3013 Big Christmas Tree
题目:http://poj.org/problem?id=3013 求每个点到1的最短路.不是最小生成树. 总是WA.看讨论里说INF至少2e10,于是真的A了! 算一下,dis最大可能3276800 ...
- vqmod for opencart插件制作进阶与技巧
FROM: http://www.sdtclass.com/4799.html 15年的时候,我写过一篇文章<略谈 vqmod for opencart 插件制作过程>,也不知道被哪些人抄 ...
- webstorm打开后无法显示文件夹目录
最近接触webstorm,上午研究怎么删除项目,不小心把项目在目录中删除了,然后重新创建时,无法显示了. 状况类似这样的 百度上搜了一些没搜到,关键字是“webstorm 项目 目录 无法显示文件夹” ...
- spring eureka required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found.
spring在集成第三方过程很容易出现类名相同,且基本作用相同的类.这样给初学者带来一定的困惑. 导致用错类而出现以下问题. required a bean of type 'com.netflix. ...
- QCheckBox控件
一个QCheckBox会有2种状态:选中和为选中.它由一个选择框和一个label组成,常常用来表示应用的某些特性是启用或不启用. 在下面的例子中,我们创建了一个选择框,它的状态变化会引起窗口标题的变化 ...
- ES之八:elasticsearch2.x下的JAVA API示例
D:\soft\elasticsearch\elasticsearch-2.1.0\lib package com.dxz.es; import java.net.InetAddress; impor ...
- 1111 Online Map (30 分)
1111 Online Map (30 分) Input our current position and a destination, an online map can recommend sev ...