• Spring boot freemarker 配置


    spring:
        datasource:
            type: com.alibaba.druid.pool.DruidDataSource
            driverClassName: com.mysql.jdbc.Driver
            url: 
            username:
            password:
        jackson:
            time-zone: GMT+8
            date-format: yyyy-MM-dd HH:mm:ss
        resources:
                static-locations: classpath:/static/,classpath:/views/
        freemarker:
          template-loader-path: classpath:/genCodeTemplateV1/
          charset: UTF-8
          content-type: text/html
       @Autowired
        private FreeMarkerConfigurer freeMarkerConfigurer;
    
        @Bean
        public Configuration getFreeMarkerConfiguration(){
            return freeMarkerConfigurer.getConfiguration();
        }
     private Map<String, Object> productMapperByTemplate(Map<String, Object> data) throws Exception {
            ProductCodeDTO productDTO = (ProductCodeDTO)data.get("productCodeDTO");
            Map dataOfTemplate = this.productTemplate(productDTO);
            String formatedTabName = productDTO.getDtoClassName().substring(0, productDTO.getDtoClassName().indexOf("DTO"));
            String templateMapperName = "template_Mapper.java";//模板名称
            String fileDir = productDTO.getTargetDir() + productDTO.getMapperPackageName().replaceAll("\.", "/");
            String fileNamePath = productDTO.getTargetDir() + productDTO.getMapperPackageName().replaceAll("\.", "/") + "/" + productDTO.getMapperClassName() + ".java";
            Template template = this.getFreeMarkerConfiguration().getTemplate(templateMapperName);//读取模板内容
            FileUtils.forceMkdir(new File(fileDir + "/"));//创建文件路径
            OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(fileNamePath), "UTF-8");
            template.process(dataOfTemplate, out); //写入文件
            out.flush();
            out.close();
            productDTO.setFormated_tab_name(formatedTabName);
            productDTO.setLower_tab_name(productDTO.getTableName().toLowerCase());
            data.put("productCodeDTO", productDTO);
            dataOfTemplate.putAll(data);
            return dataOfTemplate;
        }
  • 相关阅读:
    PHP线程安全
    Oracle中MD5+Base64加密实现
    1002. A+B for Polynomials (25)
    1001. A+B Format (20)
    Rails,uva 514
    Database,Uva1592
    Hello World for U
    D3.js 力导向图
    从零开始CSS(一 2016/9/21)
    从零开始HTML(三 2016/9/20)
  • 原文地址:https://www.cnblogs.com/yy123/p/9232534.html
Copyright © 2020-2023  润新知