zoukankan      html  css  js  c++  java
  • 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;
    }
    }

  • 相关阅读:
    Django学习笔记之Cookie、Session和自定义分页
    sass表达式前后出现空格
    render总结
    vue双向绑定补充说明方法
    mutation与action
    keep-alive使用笔记
    this指向 一般函数与箭头函数
    vue-router原理分析
    history新增方法
    常用阻止ajax缓存方法集锦
  • 原文地址:https://www.cnblogs.com/maohuidong/p/7853288.html
Copyright © 2011-2022 走看看