content: package com.example.demo.utils;
  
  import com.baomidou.mybatisplus.annotation.DbType;
  import com.baomidou.mybatisplus.annotation.IdType;
  import com.baomidou.mybatisplus.core.toolkit.StringPool;
  import com.baomidou.mybatisplus.generator.AutoGenerator;
  import com.baomidou.mybatisplus.generator.InjectionConfig;
  import com.baomidou.mybatisplus.generator.config.*;
  import com.baomidou.mybatisplus.generator.config.po.TableInfo;
  import com.baomidou.mybatisplus.generator.config.rules.DateType;
  import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
  import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * 生成工具
   *
   * @author lijia
   * @version 1.0
   * @Description 生成工具
   * @date 2020/1/8 14:25 星期三
   */
  public class MyGenerate {
  
      /**
       * RUN THIS
       */
      public static void main(String[] args) {
          // 代码生成器
          AutoGenerator mpg = new AutoGenerator();
  
          // 全局配置/Users/lijia/code/java/V2019/sdpc/sdpc-gateway
          GlobalConfig gc = new GlobalConfig();
          String projectPath = System.getProperty("user.dir");
          gc.setOutputDir("/Users/lijia/IdeaProjects/demo/src/main/java");
          gc.setAuthor("Lij");
          gc.setOpen(false);
          gc.setSwagger2(false);
          gc.setActiveRecord(true);
          gc.setIdType(IdType.ID_WORKER_STR);
          gc.setFileOverride(true);
          gc.setDateType(DateType.ONLY_DATE);
          mpg.setGlobalConfig(gc);
  
          // 数据源配置
          DataSourceConfig dsc = new DataSourceConfig();
          dsc.setDbType(DbType.MYSQL);
          dsc.setUrl("jdbc:mysql://127.0.0.1:3306/test?serverTimezone=Asia/Shanghai&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull");
          dsc.setDriverName("com.mysql.cj.jdbc.Driver");
          dsc.setUsername("root");
          dsc.setPassword("spring");
          mpg.setDataSource(dsc);
  
          // 包配置
          PackageConfig pc = new PackageConfig();
          pc.setParent("com.example.demo");
          pc.setMapper("dao");
          pc.setEntity("model");
          mpg.setPackageInfo(pc);
  
          // 自定义配置
          InjectionConfig cfg = new InjectionConfig() {
              @Override
              public void initMap() {
                  // to do nothing
              }
          };
          List<FileOutConfig> focList = new ArrayList<>();
          focList.add(new FileOutConfig("/templates/mapper.xml.ftl") {
              @Override
              public String outputFile(TableInfo tableInfo) {
                  // 自定义输入文件名称
                  return "/Users/lijia/IdeaProjects/demo/src/main/resources/mapper/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
              }
          });
          cfg.setFileOutConfigList(focList);
          mpg.setCfg(cfg);
          mpg.setTemplate(new TemplateConfig().setXml(null));
  
          // 策略配置
          StrategyConfig strategy = new StrategyConfig();
          strategy.setCapitalMode(false);
          strategy.setNaming(NamingStrategy.underline_to_camel);
          strategy.setColumnNaming(NamingStrategy.underline_to_camel);
          strategy.setEntityLombokModel(true);
          strategy.setInclude("people_config");
          // TODO 数据库Id为大写时，此时填写小写id，如果数据库为小写id，此时填写大写Id
          strategy.setSuperEntityColumns("id");
  //        strategy.setLogicDeleteFieldName("Status");
          mpg.setStrategy(strategy);
          // 选择 freemarker 引擎需要指定如下加，注意 pom 依赖必须有！
          mpg.setTemplateEngine(new FreemarkerTemplateEngine());
          mpg.execute();
      }
  }
  