• 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;
        }
  • 相关阅读:
    C# 各版本的新特性
    EntityFramework增删改查
    web.config配置文件中的configSource属性
    IOC
    权限系统设计实现
    代码依赖和解除具体依赖的技术
    ajax利用html5新特性带进度条上传文件
    React Native 从入门到原理
    npm中本地安装命令行类型的模块是不注册Path的
    需求分析-验证控件的功能需求列表
  • 原文地址:https://www.cnblogs.com/yy123/p/9232534.html
Copyright © 2020-2023  润新知