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;
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM