proxy-backend-impl-workflow
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseJava CRUD 接口实现工作流
Java CRUD Interface Implementation Workflow
为实体实现完整 CRUD 接口时,按以下 10 步逐步执行。
Follow these 10 steps to implement a complete CRUD interface for an entity.
前置准备
Preparations
- 确认实体名、模块名、表名
- 确认字段列表(类型、必填、校验规则)
- 确认功能范围(增/删/改/查/导入/导出/批量删除)
- 确认是否需要多租户隔离()
tenant_id
- Confirm entity name, module name, and table name
- Confirm field list (type, required status, validation rules)
- Confirm function scope (create/retrieve/update/delete/import/export/batch delete)
- Confirm if multi-tenant isolation is required ()
tenant_id
实施步骤
Implementation Steps
第 1 步:定义错误码
Step 1: Define Error Codes
文件:
xm-module-{模块}/.../enums/ErrorCodeConstants.javajava
ErrorCode {ENTITY}_NOT_EXISTS = new ErrorCode(1_0XX_0YY_000, "当前{实体中文名}不存在");错误码编号在已有编号段之后顺延,消息用中文。
File:
xm-module-{module}/.../enums/ErrorCodeConstants.javajava
ErrorCode {ENTITY}_NOT_EXISTS = new ErrorCode(1_0XX_0YY_000, "当前{实体中文名}不存在");The error code number should be sequential after the existing number range, and the message should be in Chinese.
第 2 步:创建 DO
Step 2: Create DO
文件:
dal/dataobject/{entity}/{Entity}DO.java继承 ,使用 + + 等注解。每个字段写 Javadoc。
BaseDO@TableName@TableId@BuilderFile:
dal/dataobject/{entity}/{Entity}DO.javaInherit , use annotations such as , , and . Write Javadoc for each field.
BaseDO@TableName@TableId@Builder第 3 步:创建 Mapper
Step 3: Create Mapper
文件:
dal/mysql/{entity}/{Entity}Mapper.java继承 ,用 方法 + 实现分页。
BaseMapperX<{Entity}DO>defaultLambdaQueryWrapperXFile:
dal/mysql/{entity}/{Entity}Mapper.javaInherit , implement pagination using methods and .
BaseMapperX<{Entity}DO>defaultLambdaQueryWrapperX第 4 步:创建 VO
Step 4: Create VO
目录:
controller/admin/{entity}/vo/| 文件 | 用途 |
|---|---|
| 分页请求,继承 |
| 创建/更新共用 |
| 响应(含导出注解) |
所有字段加 ,必填加 /。
@Schema@NotNull@NotBlankDirectory:
controller/admin/{entity}/vo/| File | Purpose |
|---|---|
| Pagination request, inherits |
| Shared for create/update operations |
| Response (includes export annotations) |
Add to all fields, and / for required fields.
@Schema@NotNull@NotBlank第 5 步:创建 Service 接口
Step 5: Create Service Interface
文件:
service/{entity}/{Entity}Service.java每个方法必须写 Javadoc。返回 DO(Controller 层转 VO)。
标准方法: / / / /
create{Entity}update{Entity}delete{Entity}get{Entity}get{Entity}PageFile:
service/{entity}/{Entity}Service.javaWrite Javadoc for every method. Return DO (Controller layer converts to VO).
Standard methods: / / / /
create{Entity}update{Entity}delete{Entity}get{Entity}get{Entity}Page第 6 步:实现 Service
Step 6: Implement Service
文件:
service/{entity}/{Entity}ServiceImpl.java- 注入 Mapper
@Resource - 写入前做业务校验(存在性、唯一性)
- 校验方法以 开头
validate - 异常用
throw exception(ErrorCode) - VO -> DO 用
BeanUtils.toBean()
File:
service/{entity}/{Entity}ServiceImpl.java- Inject Mapper using
@Resource - Perform business validation (existence, uniqueness) before writing
- Validation methods start with
validate - Throw exceptions using
throw exception(ErrorCode) - Convert VO to DO using
BeanUtils.toBean()
第 7 步:创建 Controller
Step 7: Create Controller
参照 skill 的 Controller 模板。
proxy-backend-api-design@Tag@Operation@Parameter@PreAuthorize@ValidCommonResult<T>Refer to the Controller template of the skill.
proxy-backend-api-design@Tag@Operation@Parameter@PreAuthorize@ValidCommonResult<T>第 8 步:编写 SQL
Step 8: Write SQL
- 建表 SQL(参照 skill 模板)
proxy-backend-database - 菜单 SQL(目录菜单 + 按钮权限)
- 字典 SQL(如有枚举字段需要字典展示)
- Table creation SQL (refer to the skill template)
proxy-backend-database - Menu SQL (directory menu + button permissions)
- Dictionary SQL (if enum fields need to be displayed as dictionaries)
第 9 步:自检清单
Step 9: Self-Check Checklist
- ErrorCodeConstants 已定义
- DO 继承 BaseDO,字段有注释
- Mapper 继承 BaseMapperX,分页已实现
- VO 分类正确,字段有
@Schema - Service 接口方法有 Javadoc
- ServiceImpl 校验完整
- Controller 文档注解完整,权限码正确
- 建表 SQL 包含必备字段和注释
- 菜单 SQL 权限码与 Controller 一致
- 无 TODO/FIXME,无硬编码,批量代替循环
- ErrorCodeConstants are defined
- DO inherits BaseDO, fields have comments
- Mapper inherits BaseMapperX, pagination is implemented
- VOs are correctly categorized, fields have
@Schema - Service interface methods have Javadoc
- ServiceImpl has complete validation
- Controller has complete documentation annotations and correct permission codes
- Table creation SQL includes required fields and comments
- Menu SQL permission codes match those in Controller
- No TODO/FIXME, no hardcoding, batch operations replace loops
第 10 步:输出前端对接清单
Step 10: Output Frontend Integration Checklist
完成后输出接口列表、权限码、字典类型、生成文件清单供前端使用。
详细模板见 references/frontend-checklist.md。
After completion, output the interface list, permission codes, dictionary types, and generated file list for frontend use.
For detailed template, see references/frontend-checklist.md.