• 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

  • 相关阅读:
    axios 配置
    vue 配置App.js
    vue 挂载方式
    常用的js
    vuex
    vue搭建环境
    JS中 toString() & valueOf()
    html-webpack-plugin 中使用 title选项设置模版中的值无效
    webpack为什么加载不了css?
    visual studio for mac 安装文件
  • 原文地址:https://www.cnblogs.com/lingcheng7777/p/11583663.html
Copyright © 2020-2023  润新知