|
@@ -0,0 +1,150 @@
|
|
|
|
+package com.gyee.backconfig.config;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
|
+import com.baomidou.mybatisplus.generator.AutoGenerator;
|
|
|
|
+import com.baomidou.mybatisplus.generator.config.*;
|
|
|
|
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
|
|
|
+import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
|
|
|
+
|
|
|
|
+import java.util.Scanner;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ *@ClassName GeneratorCodeConfig
|
|
|
|
+ *@Description 自动生成mybatisplus的相关代码
|
|
|
|
+ *@Author 谢生杰
|
|
|
|
+ *@Date 2020/9/25 18:26
|
|
|
|
+ *@Version 1.0
|
|
|
|
+ **/
|
|
|
|
+public class GeneratorCodeConfig {
|
|
|
|
+ public static String scanner(String tip) {
|
|
|
|
+ Scanner scanner = new Scanner(System.in);
|
|
|
|
+ StringBuilder help = new StringBuilder();
|
|
|
|
+ help.append("请输入" + tip + ":");
|
|
|
|
+ System.out.println(help.toString());
|
|
|
|
+ if (scanner.hasNext()) {
|
|
|
|
+ String ipt = scanner.next();
|
|
|
|
+ if (StringUtils.isNotEmpty(ipt)) {
|
|
|
|
+ return ipt;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ throw new MybatisPlusException("请输入正确的" + tip + "!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ System.out.println("jjjjjjjjjj");
|
|
|
|
+
|
|
|
|
+ AutoGenerator mpg = new AutoGenerator();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ GlobalConfig gc = new GlobalConfig();
|
|
|
|
+ String projectPath = System.getProperty("user.dir");
|
|
|
|
+ gc.setOutputDir(projectPath + "/src/main/java");
|
|
|
|
+ gc.setAuthor("wang");
|
|
|
|
+ gc.setOpen(false);
|
|
|
|
+
|
|
|
|
+ gc.setSwagger2(false);
|
|
|
|
+ mpg.setGlobalConfig(gc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ DataSourceConfig dsc = new DataSourceConfig();
|
|
|
|
+
|
|
|
|
+ dsc.setDriverName("com.mysql.jdbc.Driver");
|
|
|
|
+ dsc.setUsername("root");
|
|
|
|
+ dsc.setPassword("root");
|
|
|
|
+ mpg.setDataSource(dsc);*/
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ dsc.setDriverName("org.postgresql.Driver");
|
|
|
|
+ dsc.setUsername("gdprod");
|
|
|
|
+ dsc.setPassword("gd123");
|
|
|
|
+ dsc.setUrl("jdbc:postgresql://120.46.148.180:5432/wisdom");
|
|
|
|
+
|
|
|
|
+ mpg.setDataSource(dsc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ PackageConfig pc = new PackageConfig();
|
|
|
|
+
|
|
|
|
+ pc.setParent("com.gyee.backconfig");
|
|
|
|
+ pc.setEntity("model.auto");
|
|
|
|
+ pc.setMapper("mapper.auto");
|
|
|
|
+ pc.setService("service.auto");
|
|
|
|
+ pc.setServiceImpl("service.auto.impl");
|
|
|
|
+ mpg.setPackageInfo(pc);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ cfg.setFileCreate(new IFileCreate() {
|
|
|
|
+ @Override
|
|
|
|
+ public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
|
|
|
|
+
|
|
|
|
+ checkDir("调用默认方法创建的目录");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ TemplateConfig templateConfig = new TemplateConfig();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ templateConfig.setXml(null);
|
|
|
|
+ mpg.setTemplate(templateConfig);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ StrategyConfig strategy = new StrategyConfig();
|
|
|
|
+ strategy.setNaming(NamingStrategy.underline_to_camel);
|
|
|
|
+ strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
|
|
|
+ strategy.setSuperEntityClass("com.baomidou.mybatisplus.extension.activerecord.Model");
|
|
|
|
+ strategy.setEntityLombokModel(true);
|
|
|
|
+ strategy.setRestControllerStyle(true);
|
|
|
|
+
|
|
|
|
+ strategy.setEntityLombokModel(true);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
|
|
|
|
+ strategy.setControllerMappingHyphenStyle(true);
|
|
|
|
+ strategy.setTablePrefix(pc.getModuleName() + "_");
|
|
|
|
+ mpg.setStrategy(strategy);
|
|
|
|
+ mpg.setTemplateEngine(new FreemarkerTemplateEngine());
|
|
|
|
+ mpg.execute();
|
|
|
|
+ }
|
|
|
|
+}
|