use of com.baomidou.mybatisplus.generator.IFill in project shopzz by whoiszxl.
the class MyBatisFastAutoGenerator method main.
public static void main(String[] args) {
// 1.数据源配置
DataSourceConfig.Builder dataSourceConfigBuilder = new DataSourceConfig.Builder("jdbc:mysql://aliyun.whoiszxl.com/shopzz?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false", "shopzz", "ECmzyDLN7bRSKtab");
// 2.全局配置
GlobalConfig.Builder globalConfigBuilder = new GlobalConfig.Builder();
String projectPath = System.getProperty("user.dir");
globalConfigBuilder.outputDir(projectPath + "/src/main/java");
globalConfigBuilder.author(AUTHOR);
globalConfigBuilder.disableOpenDir();
if (ENABLE_SWAGGER) {
globalConfigBuilder.enableSwagger();
}
// 3.包配置
PackageConfig.Builder packageConfigBuilder = new PackageConfig.Builder();
packageConfigBuilder.parent(PACKAGE_NAME);
// 4.策略配置
StrategyConfig.Builder strategyConfigBuilder = new StrategyConfig.Builder();
// 过滤表前缀
strategyConfigBuilder.addTablePrefix("sys_", "admin_", "oms_", "ums_", "vms_", "search_", "fms_", "rms_", "wms_", "pms_", "spms_");
// 设置需要映射的表名
strategyConfigBuilder.addInclude(DB_TABLES);
// 下划线转驼峰
strategyConfigBuilder.entityBuilder().naming(NamingStrategy.underline_to_camel);
strategyConfigBuilder.entityBuilder().columnNaming(NamingStrategy.underline_to_camel);
// entity的Lombok
strategyConfigBuilder.entityBuilder().enableLombok();
// 逻辑删除
strategyConfigBuilder.entityBuilder().logicDeleteColumnName("is_deleted");
strategyConfigBuilder.entityBuilder().logicDeletePropertyName("isDeleted");
// 自动填充
// 创建时间
IFill createdAt = new Property("created_at", FieldFill.INSERT);
// 更新时间
IFill updatedAt = new Property("updated_at", FieldFill.INSERT_UPDATE);
strategyConfigBuilder.entityBuilder().addTableFills(createdAt, updatedAt);
// 乐观锁
strategyConfigBuilder.entityBuilder().versionColumnName("version");
strategyConfigBuilder.entityBuilder().versionPropertyName("version");
// 使用RestController
strategyConfigBuilder.controllerBuilder().enableRestStyle();
// 将请求地址转换为驼峰命名,如 http://localhost:8080/hello_id_2
strategyConfigBuilder.controllerBuilder().enableHyphenStyle();
// 创建代码生成器对象,加载配置 对应1.2.3.4步
AutoGenerator autoGenerator = new AutoGenerator(dataSourceConfigBuilder.build());
autoGenerator.global(globalConfigBuilder.build());
autoGenerator.packageInfo(packageConfigBuilder.build());
autoGenerator.strategy(strategyConfigBuilder.build());
// 执行
autoGenerator.execute();
}
Aggregations