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的更多相关文章
随机推荐
- iis运行asp.net页面提示“服务器应用程序不可用”的解决办法_.NET.
原因:主要是iis安装在了net framwork之后 解决办法:需要在IIS中重新注册.net 也就是要用到系统盘: cd c:\windows\microsoft.net\framework\v2 ...
- 1、搭建HBase完全分布式集群
搭建完全分布式集群 HBase集群建立在hadoop集群基础之上,所以在搭建HBase集群之前需要把Hadoop集群搭建起来,并且要考虑二者的兼容性.现在就以5台机器为例,搭建一个简单的集群. 软件版 ...
- ask 调用时间标签
织梦时间调用标签大全(2012-08-03 12:50:13) 转载▼ 分类: 织梦 织梦首页时间标签1,11-20 样式([field:pubdate function='strftime(& ...
- 用SqlConnectionStringBuilder修改连接超时时间
连接是通过参数传入,欲修改超时时间. SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder(connStr); scsb.C ...
- vscode美化方法以及定制主题插件
首先是学会调整字体和字体大小 换成你看着舒服的字体和字体大小,当然,通常情况下默认的就很好看,但每个人的显示屏参数不同显示起来的效果因人而异,如果你有更好的方案不妨设置一下 下面展示我的浅色主题和深色 ...
- SpringMVC 获取请求参数
1.获取Request response对象 在SpringMVC的注解开发中,可以选择性的接收Request和Response对象来使用 2.获取request对象请求参数 a.通过request对 ...
- python selenium-8 Page Object模式
封装空间操作为一个接口使用,而不是直接在页面中查找 from selenium import webdriver from selenium.webdriver.common.by import By ...
- jquey XMLHttpRequest cannot load url.Origin null is not allowed by Access-Control-Allow-Origin
此篇文章原文地址:http://blog.csdn.net/wangsky2/article/details/22961345 正文: 原文地址:http://stackoverflow.com/qu ...
- matplot 代码实例2
要画出如上图(注意原点有边距),怎么办呢? 简单而优雅,请看代码: #!/usr/bin/env python # coding=utf-8 import matplotlib.pyplot as p ...
- [UE4]把枪抽象为一个类