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的更多相关文章
随机推荐
- nexus7 升级失败后手动刷系统
http://bbs.gfan.com/android-6934570-1-1.html 步骤如下: 1. 下载Android系统文件,打开官方地址:https://developers.goog ...
- 标 题: 有什么办法快速把pc上的网址发送到手机上
标 题: 有什么办法快速把pc上的网址发送到手机上 transfer2u, pushbullet都可以实现你说的功能,还可以把图片或者选中内容/剪贴板内容发送到手机.后者功能更强,还支持在电脑之间发 ...
- java 的关键字 native
native native 关键字说明其修饰的方法是一个原生态方法,方法对应的实现不是在当前文件,而是在用其他语言(如C和C++)实现的文件中.Java语言本身不能对操作系统底层进行访问和操作,但是可 ...
- 什么是Map-Reduce
Map-Reduce本身并不是算法:而是一种处理模式:因为在大数据分布式这种场景下,处理数据运算和单机版不同:需要协同多台机器,并行计算:于是有了map-reduce这种模式,map阶段是数据处理,在 ...
- 【Reporting Services 报表开发】— 如何根据明细的行数实现分页(比如每隔5行分页)
一.新建报表:对于初学者可以参考我前面的文章[Reporting Services 报表开发]— 总结 如图1: 图 1 二.选择 new_name文本框—>添加组—>选择行组中的父组.具 ...
- hadoop入门篇---超详细hadoop服务器环境配置教程
虚拟机以及Linux系统安装在之前的两篇分享中已经详细的介绍了方法,并且每一步的都配图了.如果有朋友还是看不懂,那我也爱莫能助了.本篇主要就hadoop服务器操作系统配置进行详细说明,hadoop安装 ...
- !!!!!!!【unittest】unittest需要懂的的技术
https://docs.python.org/2/library/unittest.html
- netty搭建Tcp服务器实践
在netty基本组件介绍中,我们大致了解了netty的一些基本组件,今天我们来搭建一个基于netty的Tcp服务端程序,通过代码来了解和熟悉这些组件的功能和使用方法. 首先我们自己创建一个Server ...
- ubuntu 14.04 lamp 安装与配置
一.安装apache 1.打开终端:Ctrl+Alt+T sudo apt-get update 2.通过apt-get方式安装Apache: sudo apt-get install apache2 ...
- Linux修改本地时间
1.Linux时间调整 1)安装ntp(目的同步时间) yum install ntp 2)修改文件 vi /etc/ntp.conf 添加 server ntp.sjtu.edu.cn perfer ...