You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RuoYi-Vue/openspec/changes/archive/2026-06-28-refactor-backend.../design.md

55 lines
1.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Design: 后端 API 规范化设计
## API 设计规范
### RESTful 资源命名
- 使用名词复数:/api/users, /api/books
- 使用 HTTP 方法GET查询、POST创建、PUT更新、DELETE删除
- 子资源:/api/users/{id}/roles
### 统一响应格式
```java
public class ApiResponse<T> {
private int code;
private String msg;
private T data;
private long timestamp;
}
```
### 分页响应格式
```java
public class PageResponse<T> {
private int code;
private String msg;
private long total;
private List<T> rows;
}
```
### 错误码规范
- 200: 成功
- 400: 请求参数错误
- 401: 未授权
- 403: 无权限
- 404: 资源不存在
- 500: 服务器内部错误
- 业务错误码1000-9999
## 架构优化
### Controller 层
- 只负责参数校验和响应
- 业务逻辑委托给 Service
- 统一异常处理
### Service 层
- 接口与实现分离
- 事务管理
- 缓存策略
### 性能优化
- 添加 Redis 缓存
- 优化数据库查询
- 批量操作优化