mybatis-plus 代码生成器步骤:
1.添加依赖到pom.xml
<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.3</version>
</dependency>
2.main方法添加生成代码
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
//1.获取代码生成器的对象
AutoGenerator autoGenerator = new AutoGenerator();
//2.设置数据库相关配置
DataSourceConfig dataSourceConfig = new DataSourceConfig();
dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
dataSourceConfig.setUrl("jdbc:mysql://IP:3306/test_it?useUnicode=true&characterEncoding=utf-8&useSSL=false");
dataSourceConfig.setUsername("root");
dataSourceConfig.setPassword("123456");
autoGenerator.setDataSource(dataSourceConfig);
//3.设置全局配置
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setOutputDir(System.getProperty("user.dir")+"amazon/src/main/java");
globalConfig.setOpen(false);
globalConfig.setAuthor("chenshaojun");
globalConfig.setFileOverride(true);
//globalConfig.setMapperName("%sDao");
globalConfig.setIdType(IdType.ASSIGN_ID);
autoGenerator.setGlobalConfig(globalConfig);
//4.设置包名相关配置
PackageConfig packageConfig = new PackageConfig();
packageConfig.setParent("com.zhcxkjit"); //设置父报名
packageConfig.setEntity("domain");
packageConfig.setMapper("dao");
autoGenerator.setPackageInfo(packageConfig);
//5.设置策略
StrategyConfig strategyConfig = new StrategyConfig();
strategyConfig.setInclude("tb_user","tb_logger"); //设置当前参与生成的表名,可写多个
strategyConfig.setTablePrefix("tb_"); // 设置数据库的前缀名称:User(代码)=tb_user (表)
strategyConfig.setRestControllerStyle(true); //设置是否启用rest风格
strategyConfig.setVersionFieldName("version"); //设置乐观锁字段名
strategyConfig.setLogicDeleteFieldName("delteted"); //设置逻辑删除字段名
strategyConfig.setEntityLombokModel(true); //设置是否启用lombok
autoGenerator.setStrategy(strategyConfig);
//6.执行生成操作
autoGenerator.execute();
}
}
标签:代码生成,autoGenerator,strategyConfig,plus,dataSourceConfig,设置,mybatis,new,globalCon From: https://www.cnblogs.com/chenshaojun2008/p/18151806