|
@@ -0,0 +1,101 @@
|
|
|
+package com.bizmatics.fiveep.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.generator.AutoGenerator;
|
|
|
+import com.baomidou.mybatisplus.generator.config.*;
|
|
|
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author yq
|
|
|
+ * @date 2021/7/5 16:38
|
|
|
+ */
|
|
|
+public class TestUtils {
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String[] models = {"fiveep-controller", "fiveep-service", "fiveep-model", "fiveep-persistence"};
|
|
|
+ for (String model : models) {
|
|
|
+ shell(model);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void shell(String model) {
|
|
|
+
|
|
|
+ AutoGenerator mpg = new AutoGenerator();
|
|
|
+ //1、全局配置
|
|
|
+ GlobalConfig gc = new GlobalConfig();
|
|
|
+ File file = new File(model);
|
|
|
+ String path = file.getAbsolutePath();
|
|
|
+ gc.setOutputDir(path + "/src/main/java"); //生成路径(一般都是生成在此项目的src/main/java下面)
|
|
|
+ gc.setAuthor("ya"); //设置作者
|
|
|
+ gc.setOpen(false);
|
|
|
+ gc.setFileOverride(true); //第二次生成会把第一次生成的覆盖掉
|
|
|
+ gc.setServiceName("%sService"); //生成的service接口名字首字母是否为I,这样设置就没有
|
|
|
+ gc.setBaseResultMap(true); //生成resultMap
|
|
|
+ mpg.setGlobalConfig(gc);
|
|
|
+
|
|
|
+ //2、数据源配置
|
|
|
+ DataSourceConfig dsc = new DataSourceConfig();
|
|
|
+ dsc.setUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&serverTimezone=GMT&useSSL=false&characterEncoding=utf8");
|
|
|
+ dsc.setDriverName("com.mysql.jdbc.Driver");
|
|
|
+ dsc.setUsername("root");
|
|
|
+ dsc.setPassword(null);
|
|
|
+ mpg.setDataSource(dsc);
|
|
|
+
|
|
|
+ // 3、包配置
|
|
|
+ PackageConfig pc = new PackageConfig();
|
|
|
+ pc.setParent("com.bizmatics");
|
|
|
+ pc.setController("fiveep.controller.web");
|
|
|
+ pc.setEntity("model");
|
|
|
+ pc.setMapper("persistence.mapper");
|
|
|
+ pc.setService("service");
|
|
|
+ pc.setServiceImpl("service.impl");
|
|
|
+ //pc.setModuleName("test");
|
|
|
+ mpg.setPackageInfo(pc);
|
|
|
+
|
|
|
+ // 4、策略配置
|
|
|
+ StrategyConfig strategy = new StrategyConfig();
|
|
|
+ strategy.setNaming(NamingStrategy.underline_to_camel);
|
|
|
+ strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
|
|
+// strategy.setSuperControllerClass("com.lcy.demo.sys.controller.BaseController");
|
|
|
+// strategy.setSuperEntityClass("com.lcy.demo.sys.entity.BaseEntity");
|
|
|
+ // strategy.setTablePrefix("t_"); // 表名前缀
|
|
|
+ strategy.setEntityLombokModel(true); //使用lombok
|
|
|
+ strategy.setInclude("test"); // 逆向工程使用的表 如果要生成多个,这里可以传入String[]
|
|
|
+ mpg.setStrategy(strategy);
|
|
|
+
|
|
|
+ // 关闭默认 xml 生成,调整生成 至 根目录
|
|
|
+ TemplateConfig tc = new TemplateConfig();
|
|
|
+ if ("fiveep-persistence".equals(model)) {
|
|
|
+ tc.setController(null);
|
|
|
+ tc.setEntity(null);
|
|
|
+ tc.setService(null);
|
|
|
+ tc.setServiceImpl(null);
|
|
|
+ } else if ("fiveep-model".equals(model)) {
|
|
|
+ tc.setController(null);
|
|
|
+ tc.setService(null);
|
|
|
+ tc.setServiceImpl(null);
|
|
|
+ tc.setMapper(null);
|
|
|
+ tc.setXml(null);
|
|
|
+ } else if ("fiveep-service".equals(model)) {
|
|
|
+ tc.setController(null);
|
|
|
+ tc.setMapper(null);
|
|
|
+ tc.setXml(null);
|
|
|
+ tc.setEntity(null);
|
|
|
+ } else if ("fiveep-controller".equals(model)) {
|
|
|
+ tc.setMapper(null);
|
|
|
+ tc.setXml(null);
|
|
|
+ tc.setService(null);
|
|
|
+ tc.setServiceImpl(null);
|
|
|
+ tc.setEntity(null);
|
|
|
+ }
|
|
|
+ mpg.setTemplate(tc);
|
|
|
+ //5、执行
|
|
|
+ mpg.execute();
|
|
|
+ }
|
|
|
+}
|
|
|
+参考链接
|
|
|
+https://blog.csdn.net/u010559460/article/details/103945985/
|
|
|
+
|
|
|
+
|
|
|
+https://blog.csdn.net/qq_32331997/article/details/74908570
|