package generator;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.sql.Types;
import java.util.Collections;
/**
* 代码生成器
*
* @author SerLiunx
* @since 2025/8/9
*/
public class SCloudCodeGenerator {
private static final String outputPath = "C:\\Users\\serliunx\\Desktop\\code-generate";
public static void main(String[] args) {
FastAutoGenerator.create(args[0], args[1], args[2])
.globalConfig(builder -> {
builder.author("SerLiunx") // 设置作者
.outputDir(outputPath); // 指定输出目录
})
.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.serliunx.blog") // 设置父包名
.pathInfo(Collections.singletonMap(OutputFile.xml, outputPath)) // 设置mapperXml生成路径
)
.strategyConfig(builder ->
builder.addInclude("pb_article", "pb_tag", "pb_article_tag") // 设置需要生成的表名
.entityBuilder()
.enableLombok()
.disableSerialVersionUID()
.enableTableFieldAnnotation()
.controllerBuilder()
.template("/templates/controller.java")
.enableHyphenStyle()
.enableRestStyle()
.serviceBuilder()
.formatServiceFileName("%sService")
.mapperBuilder()
.disableMapperXml()
)
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
.execute();
}
}