|
@@ -0,0 +1,109 @@
|
|
|
+package cn.com.taiji.video.config;
|
|
|
+
|
|
|
+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.TableFill;
|
|
|
+import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
|
|
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
|
|
+import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description
|
|
|
+ *
|
|
|
+ * @Author yangyue
|
|
|
+ * @Date 2021/11/7
|
|
|
+ */
|
|
|
+public class MysqlGenerator {
|
|
|
+ /**
|
|
|
+ * RUN THIS
|
|
|
+ */
|
|
|
+ public static void main(String[] args) {
|
|
|
+ // 代码生成器
|
|
|
+ AutoGenerator mpg = new AutoGenerator();
|
|
|
+
|
|
|
+ // TODO 全局配置 用来设置生成文件的命名
|
|
|
+ GlobalConfig gc = new GlobalConfig();
|
|
|
+ gc.setOutputDir("E:/software/IDEA/IdeaProjects/data-service/video/src/main/java");
|
|
|
+ // 设置用户名
|
|
|
+ gc.setAuthor("yangyue");
|
|
|
+ gc.setOpen(true);
|
|
|
+ // service 命名方式
|
|
|
+ gc.setServiceName("I"+"%sService");
|
|
|
+ // service impl 命名方式
|
|
|
+ gc.setServiceImplName("%sServiceImpl");
|
|
|
+ // 自定义文件命名,注意 %s 会自动填充表实体属性!
|
|
|
+ gc.setMapperName("%sMapper");
|
|
|
+ gc.setXmlName("%sMapper");
|
|
|
+ gc.setFileOverride(true);
|
|
|
+ gc.setActiveRecord(true);
|
|
|
+ // XML 二级缓存
|
|
|
+ gc.setEnableCache(false);
|
|
|
+ // XML ResultMap
|
|
|
+ gc.setBaseResultMap(true);
|
|
|
+ // XML columList
|
|
|
+ gc.setBaseColumnList(false);
|
|
|
+ mpg.setGlobalConfig(gc);
|
|
|
+
|
|
|
+ // TODO 数据源配置
|
|
|
+ DataSourceConfig dsc = new DataSourceConfig();
|
|
|
+ dsc.setUrl("jdbc:mysql://8.140.240.182:18080/ztpt?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowMultiQueries=true");
|
|
|
+ dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
|
|
+ dsc.setUsername("root");
|
|
|
+ dsc.setPassword("Taiji@2023#data");
|
|
|
+ mpg.setDataSource(dsc);
|
|
|
+
|
|
|
+ // 包配置 文件生成后对应的包
|
|
|
+ PackageConfig pc = new PackageConfig();
|
|
|
+
|
|
|
+ pc.setParent("cn.com.taiji.video");
|
|
|
+ pc.setEntity("model");
|
|
|
+ pc.setMapper("mapper");
|
|
|
+ pc.setService("service");
|
|
|
+ pc.setServiceImpl("service.impl");
|
|
|
+ mpg.setPackageInfo(pc);
|
|
|
+
|
|
|
+ // 自定义需要填充的字段
|
|
|
+ List<TableFill> tableFillList = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ // 自定义配置
|
|
|
+ InjectionConfig cfg = new InjectionConfig() {
|
|
|
+ @Override
|
|
|
+ public void initMap() {
|
|
|
+ // to do nothing
|
|
|
+ }
|
|
|
+ };
|
|
|
+ List<FileOutConfig> focList = new ArrayList<>();
|
|
|
+ focList.add(new FileOutConfig("/templates/mapper.xml.ftl") {
|
|
|
+ @Override
|
|
|
+ public String outputFile(TableInfo tableInfo) {
|
|
|
+ // 自定义输入文件名称和生成的mapper.xml文件所在的包
|
|
|
+ return "E:/software/IDEA/IdeaProjects/data-service/video/src/main/resources/mapper/"
|
|
|
+ + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ cfg.setFileOutConfigList(focList);
|
|
|
+ mpg.setCfg(cfg);
|
|
|
+ mpg.setTemplate(new TemplateConfig().setXml(null));
|
|
|
+
|
|
|
+ // 策略配置 StrategyConfig数据表
|
|
|
+ StrategyConfig strategy = new StrategyConfig();
|
|
|
+ strategy.setNaming(NamingStrategy.underline_to_camel);
|
|
|
+ strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
|
|
+ strategy.setEntityLombokModel(true);
|
|
|
+ strategy.setRestControllerStyle(true);
|
|
|
+
|
|
|
+ // 需要生成哪些表的文件 在这里用,分开,这里生成的是style和room两个表
|
|
|
+ strategy.setInclude(new String("ht_dp_dynamic_cognition").split(","));
|
|
|
+
|
|
|
+ mpg.setStrategy(strategy);
|
|
|
+ mpg.setTemplateEngine(new FreemarkerTemplateEngine());
|
|
|
+ mpg.execute();
|
|
|
+
|
|
|
+ }
|
|
|
+}
|