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