/**
* @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的更多相关文章

随机推荐

  1. struts中指定编码(使用Filter后仍然乱码)

    https://www.cnblogs.com/oldinaction/p/5167481.html 概述: Tomcat默认是 ISO编码,不支持中文.尝试过自己写 Filter,在web.xml中 ...

  2. linux 信号与多线程

    在Linux的多线程中使用信号机制,与在进程中使用信号机制有着根本的区别,可以说是完全不同.在进程环境中,对信号的处理是,先注册信号处理函数,当信号异步发生时,调用处理函数来处理信号.它完全是异步的( ...

  3. SpringCloud统一配置笔记

    Server端: pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns= ...

  4. java web程序 String的valueOf方法总集

    在代码中用到类型转换的时候,是一个字符,然后当用户在网页中输入的是字符串, 字符转换成字符串的方法是: String.valueOf(char c);就好了 这样在写验证码的时候,网页端的就是字符串形 ...

  5. Valgrind memcheck 8种错误实例

    调不尽的内存泄漏,用不完的Valgrind Valgrind 安装 1. 到www.valgrind.org下载最新版valgrind-3.2.3.tar.bz2 2. 解压安装包:tar –jxvf ...

  6. [UE4]通过代码改变材质

    OrangeMaterial = ConstructorStatics.OrangeMaterial.Get(); , OrangeMaterial); 使用到的结构体如下: struct FCons ...

  7. https的加密解密是怎么写的?

    原文转载至:http://blog.csdn.net/aqiangsz/article/details/53611665 文章中有些不对的地方,比如用证书对改随机码进行加密,这个是不对,证书本身并没有 ...

  8. python 模块被引用多次但是里面的全局表达式总共只会执行一次

    python 模块被引用多次但是里面的全局表达式总共只会执行一次

  9. 慕课网价值149《前端JavaScript面试技巧》笔记大公开——适应群体(学生或应届毕业生)

    1.基础知识(一) http://note.youdao.com/noteshare?id=b81f56399b01da0ab5e870ea612ab94b&sub=B8ECBC1B57154 ...

  10. python应用之爬虫实战2 请求库与解析库

    知识内容: 1.requests库 2.selenium库 3.BeautifulSoup4库 4.re正则解析库 5.lxml库 参考: http://www.cnblogs.com/wupeiqi ...