| | |
| | | public class PlusCodeGenerator { |
| | | |
| | | // 数据库配置 |
| | | private static final String DB_URL = "jdbc:postgresql://lunor.cn:5431/ruoyi-java"; |
| | | private static final String DB_USERNAME = "test"; |
| | | private static final String DB_PASSWORD = "chj123456"; |
| | | private static final String DB_URL = "jdbc:postgresql://localhost:5432/ruoyi-zd"; |
| | | private static final String DB_USERNAME = "postgres"; |
| | | private static final String DB_PASSWORD = "123456"; |
| | | |
| | | // 项目基础配置 |
| | | private static final String BASE_PACKAGE = "com.ruoyi"; |
| | |
| | | public static void main(String[] args) { |
| | | String projectPath = System.getProperty("user.dir"); // 获取项目根路径 |
| | | String path = "basic-server"; // 模块名称 |
| | | String table = "test"; // 表名,多个表逗号隔开 |
| | | String table = "coal_info"; // 表名,多个表逗号隔开 |
| | | |
| | | // 代码输出路径配置 |
| | | String outputBasePath = Paths.get(projectPath, path, "src", "main", "java").toString(); |
| | |
| | | // 代码生成核心配置 |
| | | FastAutoGenerator.create(DB_URL, DB_USERNAME, DB_PASSWORD) |
| | | .globalConfig(builder -> { |
| | | builder.author("ruoyi") // 作者信息 |
| | | builder.author("ld") // 作者信息 |
| | | .outputDir(outputBasePath) // 代码输出目录 |
| | | .dateType(DateType.ONLY_DATE) // 日期类型 |
| | | .commentDate("yyyy-MM-dd") // 注释日期格式 |
| | |
| | | }) |
| | | .packageConfig(builder -> { |
| | | builder.parent(BASE_PACKAGE) // 基础包名 |
| | | .moduleName(MODULE_NAME) // 模块名 |
| | | .moduleName(MODULE_NAME) // 模块名(根据具体修改) |
| | | .entity("entity") // Entity包名 |
| | | .mapper("mapper") // Mapper包名 |
| | | .service("service") // Service包名 |
| | |
| | | |
| | | // 实体类配置 |
| | | .entityBuilder() |
| | | .superClass("com.ruoyi.common.core.domain.BaseEntity") // 继承基类 |
| | | .superClass("com.ruoyi.common.core.domain.MyBaseEntity") // 继承基类 |
| | | .addSuperEntityColumns("create_by", "create_time", "update_by", "update_time") // 排除基类字段 |
| | | .enableLombok() // 启用Lombok |
| | | .naming(NamingStrategy.underline_to_camel) // 表名转驼峰 |
| | |
| | | "create_by", "create_time", "update_by", "update_time" |
| | | )); // 基类字段 |
| | | customMap.put("idType", "AUTO"); // 主键类型 |
| | | customMap.put("superEntityClass", "com.ruoyi.common.core.domain.BaseEntity"); // 基类全路径 |
| | | customMap.put("superEntityClass", "com.ruoyi.common.core.domain.MyBaseEntity"); // 基类全路径 |
| | | customMap.put("author", "ruoyi"); // 作者信息 |
| | | customMap.put("packageName", BASE_PACKAGE + "." + MODULE_NAME); // 包名 |
| | | customMap.put("tableName", table); // 表名 |
| | |
| | | if (Files.exists(entityPath)) { |
| | | String content = Files.readString(entityPath); |
| | | content = content.replace( |
| | | "extends com.ruoyi.common.core.domain.BaseEntity", |
| | | "extends BaseEntity" |
| | | "extends com.ruoyi.common.core.domain.MyBaseEntity", |
| | | "extends MyBaseEntity" |
| | | ); // 简化基类引用 |
| | | Files.writeString(entityPath, content); |
| | | } |