🚀 数据库代码生成器
This commit is contained in:
parent
00bd461bdc
commit
e08bea215a
|
@ -28,5 +28,16 @@
|
||||||
<artifactId>jaxb-api</artifactId>
|
<artifactId>jaxb-api</artifactId>
|
||||||
<version>2.1</version>
|
<version>2.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 数据库代码生成器 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-generator</artifactId>
|
||||||
|
<version>3.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.velocity</groupId>
|
||||||
|
<artifactId>velocity-engine-core</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
package cn.bunny.common;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.PackageConfig;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||||
|
|
||||||
|
public class CodeGet {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 1、创建代码生成器
|
||||||
|
AutoGenerator mpg = new AutoGenerator();
|
||||||
|
|
||||||
|
// 2、全局配置
|
||||||
|
// 全局配置
|
||||||
|
GlobalConfig gc = new GlobalConfig();
|
||||||
|
// TODO 需要修改路径名称
|
||||||
|
gc.setOutputDir("F:\\web项目\\Bunny-Cli\\Java\\java-template\\service" + "/src/main/java");
|
||||||
|
gc.setServiceName("%sService"); // 去掉Service接口的首字母I
|
||||||
|
gc.setAuthor("bunny");
|
||||||
|
gc.setOpen(false);
|
||||||
|
mpg.setGlobalConfig(gc);
|
||||||
|
|
||||||
|
// 3、数据源配置
|
||||||
|
DataSourceConfig dsc = new DataSourceConfig();
|
||||||
|
// TODO 需要修改数据库
|
||||||
|
dsc.setUrl("jdbc:mysql://106.15.251.123:3305/guigu-oa?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true");
|
||||||
|
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
||||||
|
dsc.setUsername("root");
|
||||||
|
dsc.setPassword("02120212");
|
||||||
|
dsc.setDbType(DbType.MYSQL);
|
||||||
|
mpg.setDataSource(dsc);
|
||||||
|
|
||||||
|
// 4、包配置
|
||||||
|
PackageConfig pc = new PackageConfig();
|
||||||
|
pc.setParent("cn.bunny");
|
||||||
|
// TODO 需要修改模块名
|
||||||
|
pc.setModuleName("service");
|
||||||
|
pc.setController("controller");
|
||||||
|
pc.setService("service");
|
||||||
|
pc.setMapper("mapper");
|
||||||
|
mpg.setPackageInfo(pc);
|
||||||
|
|
||||||
|
// 5、策略配置
|
||||||
|
StrategyConfig strategy = getStrategyConfig();
|
||||||
|
mpg.setStrategy(strategy);
|
||||||
|
|
||||||
|
// 6、执行
|
||||||
|
mpg.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static StrategyConfig getStrategyConfig() {
|
||||||
|
StrategyConfig strategy = new StrategyConfig();
|
||||||
|
// TODO 要生成的表
|
||||||
|
strategy.setInclude("sys_menu", "sys_role_menu");
|
||||||
|
strategy.setNaming(NamingStrategy.underline_to_camel);// 数据库表映射到实体的命名策略
|
||||||
|
strategy.setColumnNaming(NamingStrategy.underline_to_camel);// 数据库表字段映射到实体的命名策略
|
||||||
|
strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
|
||||||
|
strategy.setRestControllerStyle(true); // restful api风格控制器
|
||||||
|
strategy.setControllerMappingHyphenStyle(true); // url中驼峰转连字符
|
||||||
|
return strategy;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue