zoukankan      html  css  js  c++  java
  • freemarker 的xml模板

    public String xmlFormwork(String xmlPath, String xmlName, String format, Map<String, Object> dataMap) {
            String xmlString = "";
            // 得FreeMarker配置对象
            // 创建Configuration对象
            Configuration cfg = new Configuration(new Version("2.3.28"));
            // 设置模板编码格式
            cfg.setEncoding(Locale.getDefault(), format);
            // 得FreeMarker的关键对象---------模板
            // 创建Template对象
            Template template = null;
            try {
                // 设置FreeMarker的模版文件位置
                cfg.setDirectoryForTemplateLoading(new File(xmlPath));
                cfg.setDefaultEncoding("UTF-8");
                template = cfg.getTemplate(xmlName);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            // String path = ServletActionContext.getServletContext().getRealPath("/");
            /*
             * File dir = new File(path + htmlPath); if (!dir.exists()) { dir.mkdirs(); }
             */
            // File fileName = new java.io.File(path + htmlPath + htmlName);
            // System.out.println("html file:" + fileName.getPath());
            // Writer writer = null;
            StringWriter w = new StringWriter();
            try {
                System.out.println(w.toString());
                // 生成xml
                template.process(dataMap, w);
                w.close();
                //
                System.out.println("w.toString()");
                System.out.println(w.toString());
                System.out.println("toString()");
                xmlString = w.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return xmlString;
        }

    xml模板参考

     https://blog.csdn.net/shuzhupeng/article/details/79981736

  • 相关阅读:
    ==和equals区别
    如何创建一个不可变类
    mysql用户的创建和授权
    事务
    Java知识点检测
    Redis
    正则表达式中match的用法
    rfind的用法
    找出文件夹里所有的文件路径
    合并多个pdf文件
  • 原文地址:https://www.cnblogs.com/lingcheng7777/p/11583663.html
Copyright © 2011-2022 走看看