mybatis-flex
mybatis-flex copied to clipboard
pgsql数据库时codegen生成类名问题
作者你好,找了很久没有发现设置codegen生成代码时类名风格的选项,目前我们的表名是类似RgReportOfAccount2MwsReport这样首字母大写的驼峰命名方式,但是生成的类名是Rgreportofaccount2mwsreport、Rgreportofaccount2mwsreportMapper类似这样的,请问这个问题当前是否有解决的方法呢
代码生成器配置如下
package com.pacvue.refund.infrastructure.util;
import com.alibaba.druid.DbType; import com.alibaba.druid.pool.DruidDataSource; import com.mybatisflex.codegen.Generator; import com.mybatisflex.codegen.config.GlobalConfig; import com.mybatisflex.codegen.dialect.IDialect; import java.net.URL;
public class Codegen {
public static void main(String[] args) {
//配置数据源
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:postgresql://xxxxxxx:5432/xxxxx");
dataSource.setDbType(DbType.postgresql);
dataSource.setUsername("xxxxxx");
dataSource.setPassword("xxxxxxx");
//创建配置内容,两种风格都可以。
GlobalConfig globalConfig = createGlobalConfigUseStyle1();
//通过 datasource 和 globalConfig 创建代码生成器
Generator generator = new Generator(dataSource, globalConfig, IDialect.POSTGRESQL);
//生成代码
generator.generate();
}
public static GlobalConfig createGlobalConfigUseStyle1() {
//创建配置内容
GlobalConfig globalConfig = new GlobalConfig();
//设置根包
// globalConfig.setBasePackage("com.pacvue.refund"); URL url = Codegen.class.getClassLoader().getResource(""); String absolutePath = url.getPath(); String modulePath = absolutePath.substring(1, absolutePath.lastIndexOf("/target")); globalConfig.setSourceDir(modulePath+"/src/main/java/com/pacvue/refund/domain"); String sourceDir = globalConfig.getSourceDir(); System.out.println(sourceDir); //设置表前缀和只生成哪些表 // globalConfig.setTablePrefix("Rg"); globalConfig.setGenerateSchema("public"); globalConfig.setGenerateTable("RgReportOfAccount2MwsReport"); // globalConfig.setGenerateTable("Account");
globalConfig.setAuthor("hejun");
globalConfig.setTableDefGenerateEnable(false);
//设置生成 entity 并启用 Lombok
globalConfig.setEntityGenerateEnable(true);
globalConfig.setEntityPackage("entity");
globalConfig.setEntityWithLombok(true);
globalConfig.setEntityWithSwagger(true);
globalConfig.setEntityDataSource("ds1");
globalConfig.setEntityJdkVersion(21);
globalConfig.setMapperGenerateEnable(true);
globalConfig.setMapperPackage("mapper");
globalConfig.setMapperOverwriteEnable(false);
globalConfig.setMapperXmlGenerateEnable(false);
globalConfig.setMapperXmlOverwriteEnable(false);
globalConfig.setServiceGenerateEnable(true);
globalConfig.setServicePackage("repository");
globalConfig.setServiceImplGenerateEnable(true);
globalConfig.setServiceImplPackage("repository.impl");
globalConfig.setControllerGenerateEnable(false);
//设置项目的JDK版本,项目的JDK为14及以上时建议设置该项,小于14则可以不设置
// globalConfig.setEntityJdkVersion(21);
//设置生成 mapper
globalConfig.setMapperGenerateEnable(true);
//可以单独配置某个列
// ColumnConfig columnConfig = new ColumnConfig(); // columnConfig.setColumnName("tenant_id"); // columnConfig.setLarge(true); // columnConfig.setVersion(true); // globalConfig.setColumnConfig("tb_account", columnConfig); return globalConfig; }
}