eliteforge-java-coding-spec
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEliteForge Java 编码规范 v1.0.0
EliteForge Java Coding Specification v1.0.0
目标
Goal
在 Java 开发任务中,依据规范提供明确的决策指引:什么应该做、什么禁止做、什么必须用什么工具/写法。引用规范条款时给出对应的 spec 行号。
Provide clear decision guidance in Java development tasks: what should be done, what is prohibited, what tools/writing methods must be used. When citing specification clauses, provide the corresponding spec line number.
执行原则
Execution Principles
-
命中即强制执行
规范中标注为"禁止"的条款,任何场景都不得妥协;标注为"必须"的条款不得降级替代。 -
代码示例优先取规范原文
需要示例时,先从中提取对应条款的原文示例,不自行臆造。references/java-coding-spec-v1.md -
最小化加载
先用检索定位 spec 行号,再局部读取;避免整篇加载。 -
明确标注来源
回答中标注对应的 spec 条款编号(如)。§3.2 POJO类
-
Enforce immediately when applicable
Clauses marked as "Prohibited" in the specification must not be compromised in any scenario; clauses marked as "Mandatory" must not be replaced with lower-level alternatives. -
Prioritize original specification examples for code samples
When examples are needed, first extract the original example of the corresponding clause from, do not create examples arbitrarily.references/java-coding-spec-v1.md -
Minimize loading
First locate the spec line number via search, then read locally; avoid loading the entire document. -
Clearly mark the source
Mark the corresponding spec clause number in the answer (e.g.,).§3.2 POJO Classes
快速检索
Quick Search
bash
undefinedbash
undefined查看 spec 行号索引
View spec line number index
cat references/toc.md
cat references/toc.md
按关键字定位条款
Locate clauses by keywords
rg -n "禁止|必须|推荐|使用|Spring|POJO|枚举|日志|事务|并发|MyBatis|服务间调用|Maven|国际化|网关|接口管理|工程" references/java-coding-spec-v1.md
rg -n "Prohibited|Mandatory|Recommended|Use|Spring|POJO|Enum|Logging|Transaction|Concurrency|MyBatis|Inter-service Call|Maven|Internationalization|Gateway|Interface Management|Project" references/java-coding-spec-v1.md
按行号读取条款(示例:100-200行)
Read clauses by line number (example: lines 100-200)
sed -n '100,200p' references/java-coding-spec-v1.md
undefinedsed -n '100,200p' references/java-coding-spec-v1.md
undefined高频问题映射
High-Frequency Problem Mapping
| 用户问题 | 规范条款 | 核心结论 |
|---|---|---|
| 枚举怎么写 | §3.3 | Enum后缀 + implements BizEnum + @Getter/@RequiredArgsConstructor |
| POJO 类怎么写 | §3.2 | UpperCamelCase + Serializable + serialVersionUID + @Accessors(chain=true) |
| 工具类用什么 | §3.4 | Apache Commons / JDK / 统一框架工具,禁止 hutool |
| 日志怎么打 | §3.6 | @Slf4j + 占位符,禁止 e.printStackTrace() |
| 循环里能调接口吗 | §3.5 | 禁止,必须封装批量接口 |
| 线程池怎么创建 | §3.7 | ThreadPoolExecutor + TransmittableThreadLocal,禁止 Executors |
| MyBatis-Plus 怎么用 | §3.8 | 禁用注解,复杂查询用 xml,keepGlobalFormat=true |
| 事务怎么处理 | §3.9 | public 方法,seata TCC,围住最小必要代码 |
| RestTemplate 能用吗 | §3.10 | 禁止,必须用 RestClient |
| Bean 怎么注入 | §3.10 | @RequiredArgsConstructor,禁止 @Autowired |
| 服务间调用用什么 | §3.11 | HttpExchangeClient + RestClient,统一框架 starter |
| Maven 版本要求 | §3.12 | JDK21 + Maven 3.9.10+ + maven wrapper |
| Controller 怎么分层 | §7.2/§7.3 | Param入参/Vo出参,分离 api/innerapi/openapi |
| 接口路径前缀 | §7.1 | /api 前端 /inner-api 内部 /open-api 开放 |
| 数据库表设计 | §4 | 主键 id + 审计字段 + tenant_id/archived/version 按需 |
| 国际化文件放哪 | §7.6 | biz/resources/i18n/ |
| smart-doc 配置 | §6 | smart-doc.json / smart-doc-innerapi.json / smart-doc-openapi.json |
| 数据库适配 SQL 放哪 | §7.7 | resources/mapper/{mysql,dm,kingbase,oceanbase}/ |
| User Question | Specification Clause | Core Conclusion |
|---|---|---|
| How to write enums | §3.3 | Enum suffix + implements BizEnum + @Getter/@RequiredArgsConstructor |
| How to write POJO classes | §3.2 | UpperCamelCase + Serializable + serialVersionUID + @Accessors(chain=true) |
| What utility classes to use | §3.4 | Apache Commons / JDK / unified framework tools, hutool is prohibited |
| How to log | §3.6 | @Slf4j + placeholders, e.printStackTrace() is prohibited |
| Can interfaces be called in loops? | §3.5 | Prohibited, batch interfaces must be encapsulated |
| How to create thread pools | §3.7 | ThreadPoolExecutor + TransmittableThreadLocal, Executors is prohibited |
| How to use MyBatis-Plus | §3.8 | Disable annotations, use xml for complex queries, keepGlobalFormat=true |
| How to handle transactions | §3.9 | Public methods, seata TCC, wrap the minimum necessary code |
| Can RestTemplate be used? | §3.10 | Prohibited, RestClient must be used |
| How to inject Beans | §3.10 | @RequiredArgsConstructor, @Autowired is prohibited |
| What to use for inter-service calls | §3.11 | HttpExchangeClient + RestClient, unified framework starter |
| Maven version requirements | §3.12 | JDK21 + Maven 3.9.10+ + maven wrapper |
| How to layer Controllers | §7.2/§7.3 | Param for input/Vo for output, separate api/innerapi/openapi |
| Interface path prefix | §7.1 | /api for frontend /inner-api for internal /open-api for external |
| Database table design | §4 | Primary key id + audit fields + tenant_id/archived/version as needed |
| Where to place internationalization files | §7.6 | biz/resources/i18n/ |
| smart-doc configuration | §6 | smart-doc.json / smart-doc-innerapi.json / smart-doc-openapi.json |
| Where to place database-adapted SQL | §7.7 | resources/mapper/{mysql,dm,kingbase,oceanbase}/ |
核心约束速查
Core Constraint Quick Reference
禁止清单(任何场景均不得妥协)
Prohibited List (No compromise in any scenario)
| 禁止项 | 必须替代 | 条款 |
|---|---|---|
| hutool | Apache Commons / JDK / 统一框架工具 | §3.4 |
| e.printStackTrace() / System.out | @Slf4j + log 占位符 | §3.6 |
| 循环/递归里调接口 | 批量接口封装 | §3.5 |
| Executors 创建线程池 | ThreadPoolExecutor | §3.7 |
| RestTemplate | Spring6 RestClient | §3.10 |
| @Value 注解读 yaml | Properties 类 | §3.10 |
| @Select/@Insert/@Update 注解 | MyBatis xml | §3.8 |
| context-path | yaml 路由配置 | §3.10 |
| lambdaQuery 多次单表查询 | xml 复杂查询 | §3.8 |
| Controller 层写业务逻辑 | Manager/Service 层 | §3.10 |
| @author JavaDoc | @since | §3.1 |
| 覆盖方式替换框架 Configuration | 扩展类或 yaml 配置 | §3.10 |
| Prohibited Item | Mandatory Alternative | Clause |
|---|---|---|
| hutool | Apache Commons / JDK / unified framework tools | §3.4 |
| e.printStackTrace() / System.out | @Slf4j + log placeholders | §3.6 |
| Calling interfaces in loops/recursion | Batch interface encapsulation | §3.5 |
| Creating thread pools with Executors | ThreadPoolExecutor | §3.7 |
| RestTemplate | Spring6 RestClient | §3.10 |
| Reading yaml with @Value annotation | Properties class | §3.10 |
| @Select/@Insert/@Update annotations | MyBatis xml | §3.8 |
| context-path | yaml route configuration | §3.10 |
| Multiple single-table queries with lambdaQuery | xml complex queries | §3.8 |
| Writing business logic in Controller layer | Manager/Service layer | §3.10 |
| @author JavaDoc | @since | §3.1 |
| Replacing framework Configuration via override | Extension class or yaml configuration | §3.10 |
必须清单
Mandatory List
| 必须项 | 说明 | 条款 |
|---|---|---|
| serialVersionUID | POJO 实现 Serializable 时必须定义 | §3.2 |
| @Accessors(chain=true) | Vo/Param/Dto 必须 | §3.2 |
| @since | 新增内容必须标识版本 | §3.1 |
| JSpecify 注解 | @Nullable/@NonNull/@NullMarked | §3.1 |
| 每成员 javadoc | POJO 枚举字段必须 | §3.1/§3.2/§3.3 |
| BizEnum | 前端/Entity 用枚举必须实现 | §3.3 |
| ResVo<T> | Controller 和服务间调用统一响应 | §3.2/§3.11 |
| HttpExchangeClient | 服务间调用必须 | §3.11 |
| keepGlobalFormat=true | @TableField 必须 | §3.8 |
| 函数式 wrapper | MyBatis-Plus wrapper 必须 | §3.8 |
| seata TCC | 分布式事务必须 | §3.9 |
| JDK21 + Maven 3.9.10+ | 必须版本 | §3.12 |
| maven wrapper | 必须使用项目 wrapper | §3.12 |
| 审计字段 | 业务表必须有 | §4 |
| api/inner-api/open-api 前缀 | Controller 路径必须 | §7.1 |
| 前端接口 Param入参/Vo出参 | Controller 必须 | §7.2 |
| 内部接口 Param入参/Dto出参 | InnerController 必须 | §7.2 |
| 开放接口独立 Dto/Param | OpenController 必须 | §7.2 |
| 并发修改加 version | 数据库必须有乐观锁字段 | §4 |
| Mandatory Item | Description | Clause |
|---|---|---|
| serialVersionUID | Must be defined when POJO implements Serializable | §3.2 |
| @Accessors(chain=true) | Mandatory for Vo/Param/Dto | §3.2 |
| @since | Must mark version for new content | §3.1 |
| JSpecify annotations | @Nullable/@NonNull/@NullMarked | §3.1 |
| Javadoc for each member | Mandatory for POJO enum fields | §3.1/§3.2/§3.3 |
| BizEnum | Must be implemented for enums used in frontend/Entity | §3.3 |
| ResVo<T> | Unified response for Controller and inter-service calls | §3.2/§3.11 |
| HttpExchangeClient | Mandatory for inter-service calls | §3.11 |
| keepGlobalFormat=true | Mandatory for @TableField | §3.8 |
| Functional wrapper | Mandatory for MyBatis-Plus wrapper | §3.8 |
| seata TCC | Mandatory for distributed transactions | §3.9 |
| JDK21 + Maven 3.9.10+ | Mandatory versions | §3.12 |
| maven wrapper | Must use project wrapper | §3.12 |
| Audit fields | Must exist in business tables | §4 |
| api/inner-api/open-api prefix | Mandatory for Controller paths | §7.1 |
| Param input/Vo output for frontend interfaces | Mandatory for Controller | §7.2 |
| Param input/Dto output for internal interfaces | Mandatory for InnerController | §7.2 |
| Independent Dto/Param for external interfaces | Mandatory for OpenController | §7.2 |
| Add version for concurrent modifications | Must have optimistic lock field in database | §4 |
工具链速查
Toolchain Quick Reference
| 场景 | 工具 | 条款 |
|---|---|---|
| 字符串拼接 | | §3.4 |
| 集合判空 | | §3.4 |
| 数组判空 | | §3.4 |
| 字符串判空 | | §3.4 |
| 字符串相等 | | §3.4 |
| 二维元组 | | §3.4 |
| 时间工具 | | §3.4 |
| JSON 工具 | | §3.4 |
| 国际化 | | §3.4 |
| 上下文 | | §3.4 |
| 服务间调用 | | §3.11 |
| 线程上下文 | | §3.7 |
| 日期格式化 | | §3.7 |
| Scenario | Tool | Clause |
|---|---|---|
| String concatenation | | §3.4 |
| Collection null check | | §3.4 |
| Array null check | | §3.4 |
| String null check | | §3.4 |
| String equality | | §3.4 |
| Two-dimensional tuple | | §3.4 |
| Time utility | | §3.4 |
| JSON utility | | §3.4 |
| Internationalization | | §3.4 |
| Context | | §3.4 |
| Inter-service calls | | §3.11 |
| Thread context | | §3.7 |
| Date formatting | | §3.7 |
分层模型速查
Layered Model Quick Reference
POJO 类分层
POJO Class Layering
Entity → ORM 实体映射,实现 Serializable
Dto → 内部数据传输
Param → Controller 入参,必须 jsr 303 validation
Vo → Controller 出参Entity → ORM entity mapping, implements Serializable
Dto → Internal data transmission
Param → Controller input, must use jsr 303 validation
Vo → Controller output各层入参出参约束
Input/Output Constraints for Each Layer
| 层级 | 入参 | 出参 |
|---|---|---|
| repository | Param / Dto | Entity / Dto |
| service | Param / Dto | Dto / Vo |
| 前端接口 Controller | Param | Vo |
| 内部接口 InnerController | Param | Dto |
| 开放接口 OpenController | Param | Dto |
| Layer | Input | Output |
|---|---|---|
| repository | Param / Dto | Entity / Dto |
| service | Param / Dto | Dto / Vo |
| Frontend Interface Controller | Param | Vo |
| Internal Interface InnerController | Param | Dto |
| External Interface OpenController | Param | Dto |
Maven 模块结构
Maven Module Structure
<service>-model POJO + MapStruct
<service>-client HttpExchangeClient 接口定义
<service>-xxx-starter 业务相关 starter
<service>-xxx-sdk 业务相关 sdk
<service>-biz 业务模块(controller/service/repository)
<service>-boot 启动模块<service>-model POJO + MapStruct
<service>-client HttpExchangeClient interface definition
<service>-xxx-starter Business-related starter
<service>-xxx-sdk Business-related sdk
<service>-biz Business module (controller/service/repository)
<service>-boot Startup modulebiz 代码分层
biz Code Layering
- biz/common/exception
- biz/common/util
- biz/模块A/controller/{innerapi, api, openapi}
- biz/模块A/service/xxxService
- biz/模块A/repository/{mapper/xxxMapper, xxxRepository}- biz/common/exception
- biz/common/util
- biz/moduleA/controller/{innerapi, api, openapi}
- biz/moduleA/service/xxxService
- biz/moduleA/repository/{mapper/xxxMapper, xxxRepository}接口路径前缀
Interface Path Prefix
- → 前端接口(需网关鉴权)
/api - → 服务间内部调用(无需鉴权)
/inner-api - → 开放接口(需开放平台鉴权)
/open-api
- → Frontend interfaces (require gateway authentication)
/api - → Internal inter-service calls (no authentication required)
/inner-api - → External interfaces (require open platform authentication)
/open-api
输出约束
Output Constraints
- 回答时必须标注规范条款编号(§章节号)
- 涉及代码示例时,从 对应条款提取,不自行编写
references/java-coding-spec-v1.md - 涉及框架/工具选型时,优先引用统一框架能力,参见
eliteforge-framework-specification - 涉及版本号时引用规范原文,不臆造具体版本
- 规范未覆盖的场景,标注"需用户补充或需外部确认"
- Must mark the specification clause number (§chapter number) when answering
- When involving code examples, extract from the corresponding clause in , do not write your own
references/java-coding-spec-v1.md - When involving framework/tool selection, prioritize referencing unified framework capabilities, see
eliteforge-framework-specification - When involving version numbers, reference the original specification, do not fabricate specific versions
- For scenarios not covered by the specification, mark "Need user supplement or external confirmation"
参考资料
Reference Materials
- 规范全文(行号索引):
references/toc.md - 规范全文:
references/java-coding-spec-v1.md
- Full specification (line number index):
references/toc.md - Full specification:
references/java-coding-spec-v1.md