|
@@ -0,0 +1,108 @@
|
|
|
+package com.usky.issue.controller;//package com.usky.iot.controller;//package com.usky.dm.controller.web.business;//package com.usky.dm.controller.web;
|
|
|
+
|
|
|
+
|
|
|
+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.NamingStrategy;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author yq
|
|
|
+ * @date 2021/7/6 11:42
|
|
|
+ */
|
|
|
+public class MybatisGeneratorUtils {
|
|
|
+ public static void main(String[] args) {
|
|
|
+
|
|
|
+ shell("service-issue","service-issue-biz");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void shell(String parentName,String model) {
|
|
|
+
|
|
|
+ AutoGenerator mpg = new AutoGenerator();
|
|
|
+ //1、全局配置
|
|
|
+ GlobalConfig gc = new GlobalConfig();
|
|
|
+// File file = new File(model);
|
|
|
+// String path = file.getAbsolutePath();
|
|
|
+ String projectPath = System.getProperty("user.dir");
|
|
|
+ projectPath+="/"+parentName;
|
|
|
+ projectPath+="/"+model;
|
|
|
+ gc.setOutputDir(projectPath+ "/src/main/java"); //生成路径(一般都是生成在此项目的src/main/java下面)
|
|
|
+ //修改为自己的名字
|
|
|
+ gc.setAuthor("han"); //设置作者
|
|
|
+ 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://172.16.120.165:3306/usky-cloud?useUnicode=true&serverTimezone=GMT&useSSL=false&characterEncoding=utf8");
|
|
|
+ dsc.setDriverName("com.mysql.jdbc.Driver");
|
|
|
+ dsc.setUsername("usky");
|
|
|
+ dsc.setPassword("Yt#75Usky");
|
|
|
+ mpg.setDataSource(dsc);
|
|
|
+
|
|
|
+ // 3、包配置
|
|
|
+ PackageConfig pc = new PackageConfig();
|
|
|
+ pc.setParent("com.usky.issue");
|
|
|
+ pc.setController("controller.web");
|
|
|
+ pc.setEntity("domain");
|
|
|
+ pc.setMapper("mapper");
|
|
|
+ pc.setService("service");
|
|
|
+ pc.setServiceImpl("service.impl");
|
|
|
+// pc.setXml("mapper.demo");
|
|
|
+ //pc.setModuleName("test");
|
|
|
+ mpg.setPackageInfo(pc);
|
|
|
+
|
|
|
+ // 4、策略配置
|
|
|
+ StrategyConfig strategy = new StrategyConfig();
|
|
|
+ strategy.setNaming(NamingStrategy.underline_to_camel);
|
|
|
+ strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
|
|
+ strategy.setSuperMapperClass("com.usky.common.mybatis.core.CrudMapper");
|
|
|
+ strategy.setSuperServiceClass("com.usky.common.mybatis.core.CrudService");
|
|
|
+ strategy.setSuperServiceImplClass("com.usky.common.mybatis.core.AbstractCrudService");
|
|
|
+ // strategy.setTablePrefix("t_"); // 表名前缀
|
|
|
+ strategy.setEntityLombokModel(true); //使用lombok
|
|
|
+ //修改自己想要生成的表
|
|
|
+ strategy.setInclude("base_alarm_notice_result"); // 逆向工程使用的表 如果要生成多个,这里可以传入String[]
|
|
|
+ mpg.setStrategy(strategy);
|
|
|
+
|
|
|
+ // 关闭默认 xml 生成,调整生成 至 根目录
|
|
|
+ //修改对应的模块名称
|
|
|
+ TemplateConfig tc = new TemplateConfig();
|
|
|
+ // 自定义配置
|
|
|
+ InjectionConfig cfg = new InjectionConfig() {
|
|
|
+ @Override
|
|
|
+ public void initMap() {
|
|
|
+ // to do nothing
|
|
|
+ }
|
|
|
+ };
|
|
|
+ //如果模板引擎是 velocity
|
|
|
+ String templatePath = "/templates/mapper.xml.vm";
|
|
|
+ // 自定义输出配置
|
|
|
+ List<FileOutConfig> focList = new ArrayList<>();
|
|
|
+ // 自定义配置会被优先输出
|
|
|
+ String finalProjectPath = projectPath;
|
|
|
+ focList.add(new FileOutConfig(templatePath) {
|
|
|
+ @Override
|
|
|
+ public String outputFile(TableInfo tableInfo) {
|
|
|
+ // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
|
|
|
+ return finalProjectPath + "/src/main/resources/mapper/issue" + "/"
|
|
|
+ + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ cfg.setFileOutConfigList(focList);
|
|
|
+ mpg.setCfg(cfg);
|
|
|
+ tc.setXml(null);
|
|
|
+ mpg.setTemplate(tc);
|
|
|
+ //5、执行
|
|
|
+ mpg.execute();
|
|
|
+ }
|
|
|
+}
|