|
@@ -0,0 +1,294 @@
|
|
|
|
+package com.usky.uskyfire.web.controller;
|
|
|
|
+
|
|
|
|
+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.io.File;
|
|
|
|
+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) {
|
|
|
|
+ String table = "uaaaa";
|
|
|
|
+ shell("",table);
|
|
|
|
+ shell1("",table);
|
|
|
|
+ shell2("",table);
|
|
|
|
+ shell3("",table);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private static void shell(String model,String table) {
|
|
|
|
+
|
|
|
|
+ AutoGenerator mpg = new AutoGenerator();
|
|
|
|
+
|
|
|
|
+ GlobalConfig gc = new GlobalConfig();
|
|
|
|
+ File file = new File(model);
|
|
|
|
+ String path = file.getAbsolutePath();
|
|
|
|
+ gc.setOutputDir(path + "/src/main/java");
|
|
|
|
+
|
|
|
|
+ gc.setAuthor("JCB");
|
|
|
|
+ gc.setOpen(false);
|
|
|
|
+ gc.setFileOverride(true);
|
|
|
|
+ gc.setServiceName("%sService");
|
|
|
|
+ gc.setBaseResultMap(true);
|
|
|
|
+ mpg.setGlobalConfig(gc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ DataSourceConfig dsc = new DataSourceConfig();
|
|
|
|
+ dsc.setUrl("jdbc:mysql://101.133.214.75:3306/usky-fire?useUnicode=true&serverTimezone=GMT&useSSL=false&characterEncoding=utf8");
|
|
|
|
+ dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
|
|
|
+ dsc.setUsername("usky");
|
|
|
|
+ dsc.setPassword("Yt#75Usky");
|
|
|
|
+ mpg.setDataSource(dsc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ PackageConfig pc = new PackageConfig();
|
|
|
|
+ pc.setParent("com.usky.uskyfire.web");
|
|
|
|
+ pc.setController("controller");
|
|
|
|
+ pc.setEntity("model");
|
|
|
|
+ pc.setMapper("persistence.mapper");
|
|
|
|
+ pc.setService("service");
|
|
|
|
+ pc.setServiceImpl("service.impl");
|
|
|
|
+
|
|
|
|
+ mpg.setPackageInfo(pc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ StrategyConfig strategy = new StrategyConfig();
|
|
|
|
+ strategy.setNaming(NamingStrategy.underline_to_camel);
|
|
|
|
+ strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ strategy.setEntityLombokModel(true);
|
|
|
|
+
|
|
|
|
+ strategy.setInclude(new String[]{""+table+""});
|
|
|
|
+ mpg.setStrategy(strategy);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ TemplateConfig tc = new TemplateConfig();
|
|
|
|
+ tc.setController(null);
|
|
|
|
+ tc.setEntity(null);
|
|
|
|
+ tc.setService(null);
|
|
|
|
+ tc.setServiceImpl(null);
|
|
|
|
+
|
|
|
|
+ InjectionConfig cfg = new InjectionConfig() {
|
|
|
|
+ @Override
|
|
|
|
+ public void initMap() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ String templatePath = "/templates/mapper.xml.vm";
|
|
|
|
+
|
|
|
|
+ List<FileOutConfig> focList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ focList.add(new FileOutConfig(templatePath) {
|
|
|
|
+ @Override
|
|
|
|
+ public String outputFile(TableInfo tableInfo) {
|
|
|
|
+
|
|
|
|
+ return path + "/src/main/resources/mapper/mysql/" + "/"
|
|
|
|
+ + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ cfg.setFileOutConfigList(focList);
|
|
|
|
+ mpg.setCfg(cfg);
|
|
|
|
+ tc.setXml(null);
|
|
|
|
+ mpg.setTemplate(tc);
|
|
|
|
+ mpg.execute();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void shell1(String model,String table) {
|
|
|
|
+
|
|
|
|
+ AutoGenerator mpg = new AutoGenerator();
|
|
|
|
+
|
|
|
|
+ GlobalConfig gc = new GlobalConfig();
|
|
|
|
+ File file = new File(model);
|
|
|
|
+ String path = file.getAbsolutePath();
|
|
|
|
+ gc.setOutputDir(path + "/src/main/java");
|
|
|
|
+
|
|
|
|
+ gc.setAuthor("JCB");
|
|
|
|
+ gc.setOpen(false);
|
|
|
|
+ gc.setFileOverride(true);
|
|
|
|
+ gc.setServiceName("%sService");
|
|
|
|
+ gc.setBaseResultMap(true);
|
|
|
|
+ mpg.setGlobalConfig(gc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ DataSourceConfig dsc = new DataSourceConfig();
|
|
|
|
+ dsc.setUrl("jdbc:mysql://101.133.214.75:3306/usky-fire?useUnicode=true&serverTimezone=GMT&useSSL=false&characterEncoding=utf8");
|
|
|
|
+ dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
|
|
|
+ dsc.setUsername("usky");
|
|
|
|
+ dsc.setPassword("Yt#75Usky");
|
|
|
|
+ mpg.setDataSource(dsc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ PackageConfig pc = new PackageConfig();
|
|
|
|
+ pc.setParent("com.usky.uskyfire.web");
|
|
|
|
+ pc.setController("controller");
|
|
|
|
+ pc.setEntity("model");
|
|
|
|
+ pc.setMapper("persistence.mapper");
|
|
|
|
+ pc.setService("service");
|
|
|
|
+ pc.setServiceImpl("service.impl");
|
|
|
|
+
|
|
|
|
+ mpg.setPackageInfo(pc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ StrategyConfig strategy = new StrategyConfig();
|
|
|
|
+ strategy.setNaming(NamingStrategy.underline_to_camel);
|
|
|
|
+ strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ strategy.setEntityLombokModel(true);
|
|
|
|
+
|
|
|
|
+ strategy.setInclude(new String[]{""+table+""});
|
|
|
|
+ mpg.setStrategy(strategy);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ TemplateConfig tc = new TemplateConfig();
|
|
|
|
+ tc.setController(null);
|
|
|
|
+ tc.setService(null);
|
|
|
|
+ tc.setServiceImpl(null);
|
|
|
|
+ tc.setMapper(null);
|
|
|
|
+ tc.setXml(null);
|
|
|
|
+ mpg.setTemplate(tc);
|
|
|
|
+ mpg.execute();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void shell2(String model,String table) {
|
|
|
|
+
|
|
|
|
+ AutoGenerator mpg = new AutoGenerator();
|
|
|
|
+
|
|
|
|
+ GlobalConfig gc = new GlobalConfig();
|
|
|
|
+ File file = new File(model);
|
|
|
|
+ String path = file.getAbsolutePath();
|
|
|
|
+ gc.setOutputDir(path + "/src/main/java");
|
|
|
|
+
|
|
|
|
+ gc.setAuthor("JCB");
|
|
|
|
+ gc.setOpen(false);
|
|
|
|
+ gc.setFileOverride(true);
|
|
|
|
+ gc.setServiceName("%sService");
|
|
|
|
+ gc.setBaseResultMap(true);
|
|
|
|
+ mpg.setGlobalConfig(gc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ DataSourceConfig dsc = new DataSourceConfig();
|
|
|
|
+ dsc.setUrl("jdbc:mysql://101.133.214.75:3306/usky-fire?useUnicode=true&serverTimezone=GMT&useSSL=false&characterEncoding=utf8");
|
|
|
|
+ dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
|
|
|
+ dsc.setUsername("usky");
|
|
|
|
+ dsc.setPassword("Yt#75Usky");
|
|
|
|
+ mpg.setDataSource(dsc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ PackageConfig pc = new PackageConfig();
|
|
|
|
+ pc.setParent("com.usky.uskyfire.web");
|
|
|
|
+ pc.setController("controller");
|
|
|
|
+ pc.setEntity("model");
|
|
|
|
+ pc.setMapper("persistence.mapper");
|
|
|
|
+ pc.setService("service");
|
|
|
|
+ pc.setServiceImpl("service.impl");
|
|
|
|
+
|
|
|
|
+ mpg.setPackageInfo(pc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ StrategyConfig strategy = new StrategyConfig();
|
|
|
|
+ strategy.setNaming(NamingStrategy.underline_to_camel);
|
|
|
|
+ strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ strategy.setEntityLombokModel(true);
|
|
|
|
+
|
|
|
|
+ strategy.setInclude(new String[]{""+table+""});
|
|
|
|
+ mpg.setStrategy(strategy);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ TemplateConfig tc = new TemplateConfig();
|
|
|
|
+ tc.setController(null);
|
|
|
|
+ tc.setMapper(null);
|
|
|
|
+ tc.setXml(null);
|
|
|
|
+ tc.setEntity(null);
|
|
|
|
+ mpg.setTemplate(tc);
|
|
|
|
+ mpg.execute();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void shell3(String model,String table) {
|
|
|
|
+
|
|
|
|
+ AutoGenerator mpg = new AutoGenerator();
|
|
|
|
+
|
|
|
|
+ GlobalConfig gc = new GlobalConfig();
|
|
|
|
+ File file = new File(model);
|
|
|
|
+ String path = file.getAbsolutePath();
|
|
|
|
+ gc.setOutputDir(path + "/src/main/java");
|
|
|
|
+
|
|
|
|
+ gc.setAuthor("JCB");
|
|
|
|
+ gc.setOpen(false);
|
|
|
|
+ gc.setFileOverride(true);
|
|
|
|
+ gc.setServiceName("%sService");
|
|
|
|
+ gc.setBaseResultMap(true);
|
|
|
|
+ mpg.setGlobalConfig(gc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ DataSourceConfig dsc = new DataSourceConfig();
|
|
|
|
+ dsc.setUrl("jdbc:mysql://101.133.214.75:3306/usky-fire?useUnicode=true&serverTimezone=GMT&useSSL=false&characterEncoding=utf8");
|
|
|
|
+ dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
|
|
|
+ dsc.setUsername("usky");
|
|
|
|
+ dsc.setPassword("Yt#75Usky");
|
|
|
|
+ mpg.setDataSource(dsc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ PackageConfig pc = new PackageConfig();
|
|
|
|
+ pc.setParent("com.usky.uskyfire.web");
|
|
|
|
+ pc.setController("controller");
|
|
|
|
+ pc.setEntity("model");
|
|
|
|
+ pc.setMapper("persistence.mapper");
|
|
|
|
+ pc.setService("service");
|
|
|
|
+ pc.setServiceImpl("service.impl");
|
|
|
|
+
|
|
|
|
+ mpg.setPackageInfo(pc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ StrategyConfig strategy = new StrategyConfig();
|
|
|
|
+ strategy.setNaming(NamingStrategy.underline_to_camel);
|
|
|
|
+ strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ strategy.setEntityLombokModel(true);
|
|
|
|
+
|
|
|
|
+ strategy.setInclude(new String[]{""+table+""});
|
|
|
|
+ mpg.setStrategy(strategy);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ TemplateConfig tc = new TemplateConfig();
|
|
|
|
+ tc.setMapper(null);
|
|
|
|
+ tc.setXml(null);
|
|
|
|
+ tc.setService(null);
|
|
|
|
+ tc.setServiceImpl(null);
|
|
|
|
+ tc.setEntity(null);
|
|
|
|
+ mpg.setTemplate(tc);
|
|
|
|
+ mpg.execute();
|
|
|
|
+ }
|
|
|
|
+}
|