MybatisGeneratorUtils.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //package com.bizmatics.mhfire.controller;
  2. //
  3. //
  4. //import com.baomidou.mybatisplus.core.toolkit.StringPool;
  5. //import com.baomidou.mybatisplus.generator.AutoGenerator;
  6. //import com.baomidou.mybatisplus.generator.InjectionConfig;
  7. //import com.baomidou.mybatisplus.generator.config.*;
  8. //import com.baomidou.mybatisplus.generator.config.po.TableInfo;
  9. //import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
  10. //
  11. //import java.io.File;
  12. //import java.util.ArrayList;
  13. //import java.util.List;
  14. //
  15. ///**
  16. // * @author yq
  17. // * @date 2021/7/6 11:42
  18. // */
  19. //public class MybatisGeneratorUtils {
  20. // public static void main(String[] args) {
  21. // //修改成自己的模块名称
  22. // String[] models = {"mhfire-controller", "mhfire-service", "mhfire-model", "mhfire-mapping"};
  23. // for (String model : models) {
  24. // shell(model);
  25. // }
  26. // }
  27. //
  28. // private static void shell(String model) {
  29. //
  30. // AutoGenerator mpg = new AutoGenerator();
  31. // //1、全局配置
  32. // GlobalConfig gc = new GlobalConfig();
  33. // File file = new File(model);
  34. // String path = file.getAbsolutePath();
  35. // gc.setOutputDir(path + "/src/main/java"); //生成路径(一般都是生成在此项目的src/main/java下面)
  36. // //修改为自己的名字
  37. // gc.setAuthor("ya"); //设置作者
  38. // gc.setOpen(false);
  39. // gc.setFileOverride(true); //第二次生成会把第一次生成的覆盖掉
  40. // gc.setServiceName("%sService"); //生成的service接口名字首字母是否为I,这样设置就没有
  41. // gc.setBaseResultMap(true); //生成resultMap
  42. // mpg.setGlobalConfig(gc);
  43. //
  44. // //2、数据源配置
  45. // //修改数据源
  46. // DataSourceConfig dsc = new DataSourceConfig();
  47. // dsc.setUrl("jdbc:mysql://101.133.214.75:3306/minhangsystem?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&characterEncoding=utf8");
  48. // dsc.setDriverName("com.mysql.jdbc.Driver");
  49. // dsc.setUsername("root");
  50. // dsc.setPassword("123456");
  51. // mpg.setDataSource(dsc);
  52. //
  53. // // 3、包配置
  54. // PackageConfig pc = new PackageConfig();
  55. // pc.setParent("com.bizmatics.mhfire");
  56. // pc.setController("controller.web");
  57. // pc.setEntity("model");
  58. // pc.setMapper("persistence.mapper");
  59. // pc.setService("service");
  60. // pc.setServiceImpl("service.impl");
  61. // //pc.setModuleName("test");
  62. // mpg.setPackageInfo(pc);
  63. //
  64. // // 4、策略配置
  65. // StrategyConfig strategy = new StrategyConfig();
  66. // strategy.setNaming(NamingStrategy.underline_to_camel);
  67. // strategy.setColumnNaming(NamingStrategy.underline_to_camel);
  68. // strategy.setSuperMapperClass("com.bizmatics.common.mvc.base.CrudMapper");
  69. // strategy.setSuperServiceClass("com.bizmatics.common.mvc.base.CrudService");
  70. // strategy.setSuperServiceImplClass("com.bizmatics.common.mvc.base.AbstractCrudService");
  71. // // strategy.setTablePrefix("t_"); // 表名前缀
  72. // strategy.setEntityLombokModel(true); //使用lombok
  73. // //修改自己想要生成的表
  74. // strategy.setInclude("zsk_team"); // 逆向工程使用的表 如果要生成多个,这里可以传入String[]
  75. // mpg.setStrategy(strategy);
  76. //
  77. // // 关闭默认 xml 生成,调整生成 至 根目录
  78. // //修改对应的模块名称
  79. // TemplateConfig tc = new TemplateConfig();
  80. // if ("mhfire-mapping".equals(model)) {
  81. // tc.setController(null);
  82. // tc.setEntity(null);
  83. // tc.setService(null);
  84. // tc.setServiceImpl(null);
  85. // // 自定义配置
  86. // InjectionConfig cfg = new InjectionConfig() {
  87. // @Override
  88. // public void initMap() {
  89. // // to do nothing
  90. // }
  91. // };
  92. // //如果模板引擎是 velocity
  93. // String templatePath = "/templates/mapper.xml.vm";
  94. // // 自定义输出配置
  95. // List<FileOutConfig> focList = new ArrayList<>();
  96. // // 自定义配置会被优先输出
  97. // focList.add(new FileOutConfig(templatePath) {
  98. // @Override
  99. // public String outputFile(TableInfo tableInfo) {
  100. // // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
  101. // return path + "/src/main/resources/mapper/mysql/" + "/"
  102. // + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
  103. // }
  104. // });
  105. // cfg.setFileOutConfigList(focList);
  106. // mpg.setCfg(cfg);
  107. // tc.setXml(null);
  108. // } else if ("mhfire-model".equals(model)) {
  109. // tc.setController(null);
  110. // tc.setService(null);
  111. // tc.setServiceImpl(null);
  112. // tc.setMapper(null);
  113. // tc.setXml(null);
  114. // } else if ("mhfire-service".equals(model)) {
  115. // tc.setController(null);
  116. // tc.setMapper(null);
  117. // tc.setXml(null);
  118. // tc.setEntity(null);
  119. // } else if ("mhfire-controller".equals(model)) {
  120. // tc.setMapper(null);
  121. // tc.setXml(null);
  122. // tc.setService(null);
  123. // tc.setServiceImpl(null);
  124. // tc.setEntity(null);
  125. // }
  126. // mpg.setTemplate(tc);
  127. // //5、执行
  128. // mpg.execute();
  129. // }
  130. //}