docs: 更新CLAUDE.md项目文档
- 完善项目架构概览和技术栈说明 - 添加开发强制要求和规范指南 - 更新常用命令和配置说明
This commit is contained in:
parent
aea6426fa3
commit
c9c1519469
86
CLAUDE.md
86
CLAUDE.md
@ -119,15 +119,61 @@ mvn test -pl coder-common-thin-web
|
||||
4. 使用`@DS("dataSourceName")`注解切换数据源
|
||||
|
||||
### 业务层开发规范
|
||||
1. **依赖注入规范**: 所有ServiceImpl实现类必须使用`@RequiredArgsConstructor`构造器注入模式
|
||||
- 在类上添加`@RequiredArgsConstructor`注解
|
||||
- 将需要注入的依赖声明为`private final`字段
|
||||
- Spring会自动通过构造器注入依赖
|
||||
1. **依赖注入规范**: 所有ServiceImpl实现类必须使用`@RequiredArgsConstructor`构造器注入模式,禁止使用`@Autowired`字段注入
|
||||
- 在类上添加`@RequiredArgsConstructor`注解
|
||||
- 将需要注入的依赖声明为`private final`字段
|
||||
- Spring会自动通过构造器注入依赖
|
||||
|
||||
2. **Service分层规范**: Service层必须按功能模块分目录组织,不允许使用单一的impl目录
|
||||
- 每个功能模块创建独立目录(如:courseselection、courseoffering、coursecart)
|
||||
- 在各功能目录下放置对应的Service接口和ServiceImpl实现类
|
||||
- 包路径示例:`org.leocoder.thin.education.service.courseselection.SysCourseSelectionService`
|
||||
- 每个功能模块创建独立目录(如:courseselection、courseoffering、coursecart)
|
||||
- 在各功能目录下放置对应的Service接口和ServiceImpl实现类
|
||||
- 包路径示例:`org.leocoder.course.education.service.courseselection.SysCourseSelectionService`
|
||||
|
||||
3. **Controller路径规范**: 所有Controller必须使用统一的`/coder`前缀作为API根路径
|
||||
- 所有Controller的`@RequestMapping`必须以`/coder`开头
|
||||
- 路径格式:`/coder/模块名/功能名`
|
||||
- 示例路径:`/coder/education/selection`、`/coder/education/offering`、`/coder/education/cart`
|
||||
- 参考示例:`@RequestMapping("/coder/education/selection")`
|
||||
|
||||
4. **Controller权限验证规范**: 所有Controller的接口方法必须配置权限验证
|
||||
- **强制要求**: 每个Controller方法都必须添加`@SaCheckPermission`注解
|
||||
- **导入依赖**: 在Controller类中导入`import cn.dev33.satoken.annotation.SaCheckPermission;`
|
||||
- **权限命名规范**: 使用格式`模块名:功能名:操作名`
|
||||
- 教育模块示例:`@SaCheckPermission("education:selection:list")`
|
||||
- 系统模块示例:`@SaCheckPermission("system:user:list")`
|
||||
- **操作名对应关系**:
|
||||
- `list` - 查询列表
|
||||
- `page` - 分页查询
|
||||
- `detail` - 查询详情
|
||||
- `add` - 新增
|
||||
- `edit` - 修改
|
||||
- `delete` - 删除
|
||||
- `status` - 状态变更
|
||||
- `import` - 导入
|
||||
- `export` - 导出
|
||||
- **示例代码**:
|
||||
```java
|
||||
@RestController
|
||||
@RequestMapping("/coder/education/selection")
|
||||
public class SysCourseSelectionController {
|
||||
|
||||
@SaCheckPermission("education:selection:list")
|
||||
@GetMapping("/list")
|
||||
public List<SysCourseSelection> list(@Validated CourseSelectionBo bo) {
|
||||
// 业务逻辑
|
||||
}
|
||||
|
||||
@SaCheckPermission("education:selection:add")
|
||||
@PostMapping("/add")
|
||||
public String add(@Validated CourseSelectionBo bo) {
|
||||
// 业务逻辑
|
||||
}
|
||||
}
|
||||
```
|
||||
- **禁止行为**:
|
||||
- 严禁创建没有权限验证的Controller方法
|
||||
- 严禁在Sa-Token配置中添加业务接口的排除路径
|
||||
- 严禁通过其他方式绕过权限验证
|
||||
|
||||
### 工具类使用
|
||||
项目提供了丰富的工具类,位于`coder-common-thin-common/utils`:
|
||||
@ -158,3 +204,29 @@ mvn test -pl coder-common-thin-web
|
||||
- 数据库操作优先使用MyBatis Plus提供的方法
|
||||
- 安全认证统一使用Sa-Token,避免重复造轮子
|
||||
- 工具类使用前先检查是否已有现成实现
|
||||
|
||||
## 重要规范文档
|
||||
|
||||
- 所有Controller必须配置权限验证(强制要求)
|
||||
- 使用统一的路径前缀和权限命名规范
|
||||
- 遵循标准的代码结构和注解使用规范
|
||||
|
||||
## 开发强制要求 ⚠️
|
||||
|
||||
1. **权限验证强制要求**: 任何新增的Controller方法都必须添加 `@SaCheckPermission` 注解
|
||||
2. **禁止绕过权限验证**: 严禁通过排除路径或其他方式绕过Sa-Token权限验证
|
||||
3. **权限命名标准化**: 必须使用 `模块名:功能名:操作名` 格式命名权限
|
||||
4. **构造器注入**: 必须使用 `@RequiredArgsConstructor` 模式,禁用 `@Autowired`
|
||||
5. **模块依赖管理**: 新增业务模块时必须在Web启动模块(`coder-course-web`)的pom.xml中添加对应依赖
|
||||
- **依赖检查原则**: 当Controller接口报错被当作静态资源处理时,首先检查Web模块是否缺少对应业务模块的依赖
|
||||
- **依赖添加规范**: 在`coder-course-web/pom.xml`中添加业务模块依赖,确保Spring Boot能扫描到所有Controller
|
||||
- **示例依赖配置**:
|
||||
```xml
|
||||
<!-- 学生选课管理系统模块 -->
|
||||
<dependency>
|
||||
<groupId>org.leocoder.course</groupId>
|
||||
<artifactId>coder-course-education</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
```
|
||||
- **验证方法**: 添加依赖后重新编译和启动应用程序,确保所有Controller接口能正常访问
|
||||
Loading…
Reference in New Issue
Block a user