优化规则

This commit is contained in:
马宝龙
2026-07-28 11:59:31 +08:00
parent 52cbed63a8
commit f9dcf890b2
2 changed files with 62 additions and 8 deletions

View File

@@ -34,14 +34,9 @@
## 后端规则 ## 后端规则
- 类型名使用大驼峰,变量名和方法名使用小驼峰 - 代码须符合阿里巴巴Java开发规范、springboot框架规范、其他使用到的框架、中间件规范
- 采用四层结构:`controller``service``mapper``domain` - 代码须简洁明了,不能冗杂
- `controller` 层声明接口,为前端提供 API - 能通用的代码最好通用
- `service` 层声明业务接口,`impl` 子目录负责实现业务逻辑。
- `mapper` 层包含 Mapper 接口和 XML 文件,负责数据库操作。
- `domain` 层包含 POJO、DTO 等领域对象。
- 方法参数不要使用 `Map`;需要结构化参数时创建对应的 DTO 类。
- 使用 Lombok 的 `@RequiredArgsConstructor` 完成依赖注入。
## API 规范 ## API 规范

59
backend/AGENTS.md Normal file
View File

@@ -0,0 +1,59 @@
# 后端开发规则
## 技术栈
- Spring Boot 3.4.5、Java 21、MyBatis-Plus、mysql 8、redis
## 总体规则
- 代码须符合阿里巴巴Java开发规范、springboot框架规范、其他使用到的框架、中间件规范。
## 项目结构(不可变)
后端源码必须遵循以下目录结构:
```text
backend/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/example/training/
│ │ │ ├── TrainingApplication.java # 启动类(@SpringBootApplication
│ │ │ ├── config/ # @Configuration 配置类
│ │ │ │ ├── MybatisPlusConfig.java
│ │ │ │ └── SecurityConfig.java
│ │ │ ├── constant/ # 常量类
│ │ │ │ └── Constants.java
│ │ │ ├── enums/ # 枚举
│ │ │ │ └── UserTypeEnum.java
│ │ │ ├── controller/ # @RestControllerHTTP 入口
│ │ │ │ └── UserController.java
│ │ │ ├── service/ # @Service业务逻辑
│ │ │ │ ├── UserService.java # 接口
│ │ │ │ └── impl/UserServiceImpl.java # 实现
│ │ │ ├── mapper/ # @Mapper数据访问
│ │ │ │ └── UserMmapper.java
│ │ │ ├── domain
│ │ │ │ └── entity/ # @Entity数据库映射
│ │ │ │ └── User.java
│ │ │ │ ├── dto/ # 请求对象
│ │ │ │ └── UserDto.java
│ │ │ │ ├── vo/ # 响应对象
│ │ │ │ └── UserVo.java
│ │ │ ├── exception/ # 自定义异常 + 全局处理器
│ │ │ │ ├── ServiceException.java
│ │ │ │ └── GlobalExceptionHandler.java
│ │ │ └── util/ # 工具类
│ │ └── resources/
│ │ ├── application.yml # 主配置(也可用 .properties
│ │ ├── static/ # CSS/JS/图片等静态资源
│ │ ├── templates/ # 模板
│ │ ├── logback-spring.xml # 日志配置
│ │ └── mapper # mapper文件
│ │ └── User.xml
│ └── test/
│ └── java/com/example/training/ # 测试代码,包结构镜像 main
│ ├── MyappApplicationTests.java
│ ├── controller/UserControllerTest.java
│ └── service/UserServiceTest.java
```