123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- 1添加依赖
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-generator</artifactId>
- <version>3.3.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.velocity</groupId>
- <artifactId>velocity-engine-core</artifactId>
- <version>2.1</version>
- </dependency>
- 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;
- 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();
-
- GlobalConfig gc = new GlobalConfig();
- File file = new File(model);
- String path = file.getAbsolutePath();
- gc.setOutputDir(path + "/src/main/java");
-
- gc.setAuthor("ya");
- gc.setOpen(false);
- gc.setFileOverride(true);
- gc.setServiceName("%sService");
- gc.setBaseResultMap(true);
- mpg.setGlobalConfig(gc);
-
-
- 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);
-
-
- 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");
-
- mpg.setPackageInfo(pc);
-
- StrategyConfig strategy = new StrategyConfig();
- strategy.setNaming(NamingStrategy.underline_to_camel);
- strategy.setColumnNaming(NamingStrategy.underline_to_camel);
- strategy.setSuperMapperClass("com.bizmatics.common.mvc.base.CrudMapper");
- strategy.setSuperServiceClass("com.bizmatics.common.mvc.base.CrudService");
- strategy.setSuperServiceImplClass("com.bizmatics.common.mvc.base.AbstractCrudService");
-
- strategy.setEntityLombokModel(true);
- strategy.setInclude("test");
- mpg.setStrategy(strategy);
-
- 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);
-
- mpg.execute();
- }
- }
- 参考链接
- https:
- https:
|