package com.snail.code.system;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.sql.Types;
import java.util.Collections;
/**
* @author 熟透的蜗牛
* @version 1.0
* @description: 系统库生成代码
* @date 2025/1/16 17:00
*/
public class SystemGenerator {
public static void generate() {
FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/snail-system?serverTimezone=Asia/Shanghai", "root", "root")
.globalConfig(builder -> {
builder.author("熟透的蜗牛") // 设置作者
.enableSwagger() // 开启 swagger 模式
.outputDir("D://system") // 指定输出目录
.dateType(DateType.ONLY_DATE) // 设置时间类型策略
.commentDate("yyyy-MM-dd")// 设置注释日期格式
.disableOpenDir();//自动打开目录
})
.dataSourceConfig(builder ->
builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
int typeCode = metaInfo.getJdbcType().TYPE_CODE;
if (typeCode == Types.SMALLINT) {
// 自定义类型转换
return DbColumnType.INTEGER;
}
return typeRegistry.getColumnType(metaInfo);
})
)
.packageConfig(builder ->
builder.parent("com.snail") // 设置父包名
.moduleName("system") // 设置父包模块名
.entity("model") // 设置 Entity 包名
.service("service") // 设置 Service 包名
.serviceImpl("service.impl") // 设置 Service Impl 包名
.mapper("mapper") // 设置 Mapper 包名
.xml("mappers") // 设置 Mapper XML 包名
.controller("controller")// 设置 Controller 包名
.pathInfo(Collections.singletonMap(OutputFile.xml, "D://system")) // 设置mapperXml生成路径
)
.strategyConfig(builder ->
builder
//.addInclude("") // 设置需要生成的表名
.addTablePrefix("sys_") // 设置过滤表前缀
.entityBuilder()
.enableLombok()
.serviceBuilder()
.formatServiceFileName("%sService")
.formatServiceImplFileName("%sServiceImp")
//这里配置的mybatis-plus-join 框架的包
.superServiceClass("com.github.yulichang.base.MPJBaseService")
.superServiceImplClass("com.github.yulichang.base.MPJBaseServiceImpl")
.mapperBuilder().superClass("com.github.yulichang.base.MPJBaseMapper")
.controllerBuilder().superClass("com.snail.manager.common.resdata.BaseController")
.enableRestStyle()
)
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
.execute();
System.out.println("执行完成");
}
}
01-06
2464

12-28
285

11-02
504

10-10
1814

11-20
1109
