feat :AIOJ 后端模块并更新项目结构
- 引入了新模块:gateway、judge service、question service、user service 和 UPMS。 - 在 gateway 和 user service 模块中创建了 package-info.java 文件用于文档说明。 - 更新了 pom.xml 文件以反映新的模块结构和依赖关系。 - 在 UserController 中实现了基本的用户资料管理端点。 - 为每个新模块添加了扁平化 POM 文件以有效管理依赖。 - 增强了项目属性,以实现更好的版本管理和模块间一致性。
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.meowrain.aioj</groupId>
|
||||
<artifactId>aioj-backend-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>aioj-backend-common-mybatis</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<description>AIOJ MyBatis Plus 封装</description>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.meowrain.aioj</groupId>
|
||||
<artifactId>aioj-backend-common-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -3,22 +3,17 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.meowrain</groupId>
|
||||
<groupId>cn.meowrain.aioj</groupId>
|
||||
<artifactId>aioj-backend-common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>aioj-backend-common-mybatis</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<description>AIOJ MyBatis Plus 封装</description>
|
||||
|
||||
<description>aioj mybatis 封装</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!--hutool-->
|
||||
<dependency>
|
||||
@@ -52,9 +47,20 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.meowrain</groupId>
|
||||
<groupId>cn.meowrain.aioj</groupId>
|
||||
<artifactId>aioj-backend-common-core</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ==================== 代码生成器 (test scope) ==================== -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,119 @@
|
||||
package cn.meowrain.aioj.generator;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
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.NamingStrategy;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
import com.baomidou.mybatisplus.generator.fill.Column;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* MyBatis Plus 代码生成器
|
||||
* <p>
|
||||
* 使用方法:
|
||||
* 1. 修改下方的数据库连接配置
|
||||
* 2. 修改要生成的表名
|
||||
* 3. 修改输出路径和包名
|
||||
* 4. 运行 main 方法
|
||||
* </p>
|
||||
*
|
||||
* @author meowrain
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class CodeGenerator {
|
||||
|
||||
// ==================== 数据库配置 ====================
|
||||
/** 数据库地址 */
|
||||
private static final String DB_URL = "jdbc:mysql://10.0.0.10:3306/aioj?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai";
|
||||
/** 数据库用户名 */
|
||||
private static final String DB_USERNAME = "root";
|
||||
/** 数据库密码 */
|
||||
private static final String DB_PASSWORD = "123456";
|
||||
|
||||
// ==================== 代码生成配置 ====================
|
||||
/** 作者名 */
|
||||
private static final String AUTHOR = "meowrain";
|
||||
/** 父包名 */
|
||||
private static final String PARENT_PACKAGE = "cn.meowrain.aioj.backend";
|
||||
/** 模块名 (如: userservice, questionservice) */
|
||||
private static final String MODULE_NAME = "userservice";
|
||||
/** 要生成的表名 (多个表用逗号分隔) */
|
||||
private static final String[] TABLE_NAMES = {"sys_user", "sys_role"};
|
||||
/** 表前缀 (生成时会去掉前缀) */
|
||||
private static final String[] TABLE_PREFIX = {"sys_", "t_"};
|
||||
|
||||
// ==================== 输出路径配置 ====================
|
||||
/** 代码输出目录 (默认当前项目的 src/main/java) */
|
||||
private static final String OUTPUT_DIR = System.getProperty("user.dir") + "/src/main/java";
|
||||
/** Mapper XML 输出目录 */
|
||||
private static final String MAPPER_XML_DIR = System.getProperty("user.dir") + "/src/main/resources/mapper";
|
||||
|
||||
public static void main(String[] args) {
|
||||
generateCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行代码生成
|
||||
*/
|
||||
public static void generateCode() {
|
||||
FastAutoGenerator.create(DB_URL, DB_USERNAME, DB_PASSWORD)
|
||||
// 全局配置
|
||||
.globalConfig(builder -> builder
|
||||
.author(AUTHOR)
|
||||
.outputDir(OUTPUT_DIR)
|
||||
.dateType(DateType.TIME_PACK) // 使用 Java 8 日期类型
|
||||
.commentDate("yyyy-MM-dd")
|
||||
.disableOpenDir() // 生成后不打开目录
|
||||
)
|
||||
// 包配置
|
||||
.packageConfig(builder -> builder
|
||||
.parent(PARENT_PACKAGE)
|
||||
.moduleName(MODULE_NAME)
|
||||
.entity("dao.entity")
|
||||
.mapper("dao.mapper")
|
||||
.service("service")
|
||||
.serviceImpl("service.impl")
|
||||
.controller("controller")
|
||||
.xml("mapper")
|
||||
.pathInfo(Collections.singletonMap(OutputFile.xml, MAPPER_XML_DIR))
|
||||
)
|
||||
// 策略配置
|
||||
.strategyConfig(builder -> builder
|
||||
.addInclude(TABLE_NAMES)
|
||||
.addTablePrefix(TABLE_PREFIX)
|
||||
// Entity 策略
|
||||
.entityBuilder()
|
||||
.enableLombok()
|
||||
.enableTableFieldAnnotation()
|
||||
.naming(NamingStrategy.underline_to_camel)
|
||||
.columnNaming(NamingStrategy.underline_to_camel)
|
||||
.idType(IdType.ASSIGN_ID) // 雪花算法ID
|
||||
.addTableFills(new Column("create_time", FieldFill.INSERT))
|
||||
.addTableFills(new Column("update_time", FieldFill.INSERT_UPDATE))
|
||||
.logicDeleteColumnName("del_flag")
|
||||
.logicDeletePropertyName("delFlag")
|
||||
// Mapper 策略
|
||||
.mapperBuilder()
|
||||
.enableBaseResultMap()
|
||||
.enableBaseColumnList()
|
||||
// Service 策略
|
||||
.serviceBuilder()
|
||||
.formatServiceFileName("%sService")
|
||||
.formatServiceImplFileName("%sServiceImpl")
|
||||
// Controller 策略
|
||||
.controllerBuilder()
|
||||
.enableRestStyle()
|
||||
)
|
||||
// 模板引擎
|
||||
.templateEngine(new FreemarkerTemplateEngine())
|
||||
.execute();
|
||||
|
||||
System.out.println("========== 代码生成完成 ==========");
|
||||
System.out.println("输出目录: " + OUTPUT_DIR);
|
||||
System.out.println("Mapper XML: " + MAPPER_XML_DIR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package cn.meowrain.aioj.generator;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
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.NamingStrategy;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
import com.baomidou.mybatisplus.generator.fill.Column;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* 交互式代码生成器
|
||||
* <p>
|
||||
* 运行后会在控制台提示输入相关配置信息
|
||||
* </p>
|
||||
*
|
||||
* @author meowrain
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class InteractiveCodeGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
System.out.println("========== AIOJ 代码生成器 ==========");
|
||||
System.out.println();
|
||||
|
||||
// 数据库配置
|
||||
System.out.print("请输入数据库地址 (默认: localhost:3306/aioj): ");
|
||||
String dbHost = scanner.nextLine().trim();
|
||||
if (dbHost.isEmpty()) {
|
||||
dbHost = "localhost:3306/aioj";
|
||||
}
|
||||
String dbUrl = "jdbc:mysql://" + dbHost + "?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai";
|
||||
|
||||
System.out.print("请输入数据库用户名 (默认: root): ");
|
||||
String dbUsername = scanner.nextLine().trim();
|
||||
if (dbUsername.isEmpty()) {
|
||||
dbUsername = "root";
|
||||
}
|
||||
|
||||
System.out.print("请输入数据库密码: ");
|
||||
String dbPassword = scanner.nextLine().trim();
|
||||
|
||||
// 代码配置
|
||||
System.out.print("请输入模块名 (如 userservice, questionservice): ");
|
||||
String moduleName = scanner.nextLine().trim();
|
||||
|
||||
System.out.print("请输入要生成的表名 (多个表用逗号分隔): ");
|
||||
String tableInput = scanner.nextLine().trim();
|
||||
String[] tableNames = tableInput.split(",");
|
||||
|
||||
System.out.print("请输入表前缀 (如 sys_,t_ 留空则不去除前缀): ");
|
||||
String prefixInput = scanner.nextLine().trim();
|
||||
String[] tablePrefixes = prefixInput.isEmpty() ? new String[]{} : prefixInput.split(",");
|
||||
|
||||
System.out.print("请输入输出目录 (留空使用当前目录): ");
|
||||
String outputDir = scanner.nextLine().trim();
|
||||
if (outputDir.isEmpty()) {
|
||||
outputDir = System.getProperty("user.dir") + "/src/main/java";
|
||||
}
|
||||
|
||||
String mapperXmlDir = outputDir.replace("/java", "/resources") + "/mapper";
|
||||
|
||||
System.out.println();
|
||||
System.out.println("========== 配置确认 ==========");
|
||||
System.out.println("数据库: " + dbUrl);
|
||||
System.out.println("模块名: " + moduleName);
|
||||
System.out.println("表名: " + String.join(", ", tableNames));
|
||||
System.out.println("输出目录: " + outputDir);
|
||||
System.out.println();
|
||||
System.out.print("确认生成? (y/n): ");
|
||||
|
||||
String confirm = scanner.nextLine().trim().toLowerCase();
|
||||
if (!confirm.equals("y") && !confirm.equals("yes")) {
|
||||
System.out.println("已取消生成");
|
||||
return;
|
||||
}
|
||||
|
||||
// 执行生成
|
||||
generate(dbUrl, dbUsername, dbPassword, moduleName, tableNames, tablePrefixes, outputDir, mapperXmlDir);
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
private static void generate(String dbUrl, String dbUsername, String dbPassword,
|
||||
String moduleName, String[] tableNames, String[] tablePrefixes,
|
||||
String outputDir, String mapperXmlDir) {
|
||||
FastAutoGenerator.create(dbUrl, dbUsername, dbPassword)
|
||||
// 全局配置
|
||||
.globalConfig(builder -> builder
|
||||
.author("meowrain")
|
||||
.outputDir(outputDir)
|
||||
.dateType(DateType.TIME_PACK)
|
||||
.commentDate("yyyy-MM-dd")
|
||||
.disableOpenDir()
|
||||
)
|
||||
// 包配置
|
||||
.packageConfig(builder -> builder
|
||||
.parent("cn.meowrain.aioj.backend")
|
||||
.moduleName(moduleName)
|
||||
.entity("dao.entity")
|
||||
.mapper("dao.mapper")
|
||||
.service("service")
|
||||
.serviceImpl("service.impl")
|
||||
.controller("controller")
|
||||
.xml("mapper")
|
||||
.pathInfo(Collections.singletonMap(OutputFile.xml, mapperXmlDir))
|
||||
)
|
||||
// 策略配置
|
||||
.strategyConfig(builder -> {
|
||||
builder.addInclude(tableNames);
|
||||
if (tablePrefixes.length > 0) {
|
||||
builder.addTablePrefix(tablePrefixes);
|
||||
}
|
||||
builder
|
||||
// Entity 策略
|
||||
.entityBuilder()
|
||||
.enableLombok()
|
||||
.enableTableFieldAnnotation()
|
||||
.naming(NamingStrategy.underline_to_camel)
|
||||
.columnNaming(NamingStrategy.underline_to_camel)
|
||||
.idType(IdType.ASSIGN_ID)
|
||||
.addTableFills(new Column("create_time", FieldFill.INSERT))
|
||||
.addTableFills(new Column("update_time", FieldFill.INSERT_UPDATE))
|
||||
.logicDeleteColumnName("del_flag")
|
||||
.logicDeletePropertyName("delFlag")
|
||||
// Mapper 策略
|
||||
.mapperBuilder()
|
||||
.enableBaseResultMap()
|
||||
.enableBaseColumnList()
|
||||
// Service 策略
|
||||
.serviceBuilder()
|
||||
.formatServiceFileName("%sService")
|
||||
.formatServiceImplFileName("%sServiceImpl")
|
||||
// Controller 策略
|
||||
.controllerBuilder()
|
||||
.enableRestStyle();
|
||||
})
|
||||
// 模板引擎
|
||||
.templateEngine(new FreemarkerTemplateEngine())
|
||||
.execute();
|
||||
|
||||
System.out.println();
|
||||
System.out.println("========== 代码生成完成 ==========");
|
||||
System.out.println("Java 代码: " + outputDir);
|
||||
System.out.println("Mapper XML: " + mapperXmlDir);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user