Install
openclaw skills install java-standards-alibabaUse when writing or modifying Java code — enforces Alibaba Java Development Guidelines (嵩山版) for naming, formatting, OOP, collections, concurrency, control statements, exceptions, logging, MySQL, security, and project structure. Activates for any Java code generation, code review, or code modification task.
openclaw skills install java-standards-alibaba在任何 Java 代码的编写、修改、审查场景中,必须严格遵守本规范。 规约等级:【强制】>【推荐】>【参考】
本 skill 在以下场景中自动激活并强制执行:
根据当前代码任务,定位适用的规约分类:
| 场景 | 定位规约 |
|---|---|
| 定义类名/方法名/变量名 | references/naming.md — 命名风格 |
| 定义常量 | references/constants.md — 常量定义 |
| 编写/格式化代码 | references/code-format.md — 代码格式 |
| 编写类/接口/对象 | references/oop.md — OOP 规约 |
| 处理日期时间 | references/date-time.md — 日期时间 |
| 使用集合(List/Map/Set) | references/collections.md — 集合处理 |
| 编写并发/多线程代码 | references/concurrency.md — 并发处理 |
| 编写条件/循环逻辑 | references/control-flow.md — 控制语句 |
| 编写注释 | references/comments.md — 注释规约 |
| 设计 REST API / 前后端交互 | references/api-contract.md — 前后端规约 |
| 正则 / BeanUtils / Velocity 等 | references/others.md — 其他 |
| 异常处理 / 错误码 | references/exceptions.md — 异常日志 |
| 日志打印 | references/logging.md — 日志规约 |
| 编写单元测试 | references/unit-test.md — 单元测试 |
| 安全检查 / 输入校验 | references/security.md — 安全规约 |
| 建表 / 索引 | references/mysql-ddl.md — MySQL 建表规约 |
| 索引设计 | references/mysql-index.md — MySQL 索引规约 |
| 编写 SQL | references/mysql-sql.md — MySQL SQL 语句 |
| MyBatis / ORM 映射 | references/orm.md — ORM 映射 |
| 项目分层 / 依赖 | references/project-structure.md — 工程结构 |
| 系统设计 | references/design.md — 设计规约 |
在生成/修改代码之前,必须读取对应 reference 文件,逐条对照【强制】规则。
按照规约要求编写代码,注意:
代码生成后,逐项对照以下通用自查(适用于所有 Java 代码任务):
UpperCamelCase,方法/变量 lowerCamelCaseis 前缀Enum 后缀,成员全大写@Overrideequals 用常量/确定值调用,整型包装类用 equals 比较BigDecimal 比较,BigDecimal 用 compareTotoStringequals 时覆写了 hashCodeisEmpty() 判空而非 size()==0Collectors.toMap() 使用了 mergeFunctionforeach 中无 remove/add 操作ExecutorsSimpleDateFormat 非 static 或用 ThreadLocalThreadLocal 在 finally 中 remove()try 外获取,finally 中释放switch 有 default,每个 case 有 break/returnif/else/for/while 使用大括号Throwable 拦截System.out / e.printStackTrace()SELECT *bigint unsigned 自增,必备字段 id, create_time, update_timedecimal,不用 float/double#{} 不用 ${}类名: UpperCamelCase (例外: DO/DTO/VO/BO/AO/PO/UID)
方法/变量: lowerCamelCase
常量: ALL_UPPER_CASE
包名: alllowercase.singular
数组: int[] array (不是 String args[])
枚举: XxxEnum.SOME_VALUE
抽象类: AbstractXxx / BaseXxx
异常类: XxxException
测试类: XxxTest
Service: XxxService (接口) / XxxServiceImpl (实现)
缩进: 4 空格,禁止 Tab
行宽: ≤ 120 字符
空格: if/for/while + 空格 + (
运算符左右各一空格
注释 // 后一空格
括号: 左大括号前空格,不换行
编码: UTF-8,Unix 换行
| 陷阱 | 正确做法 |
|---|---|
Integer a == Integer b | a.equals(b) |
float a == float b | Math.abs(a-b) < epsilon 或 BigDecimal |
BigDecimal(double) | new BigDecimal("0.1") 或 BigDecimal.valueOf(0.1) |
BigDecimal.equals() | BigDecimal.compareTo() |
new Date().getTime() | System.currentTimeMillis() |
SimpleDateFormat static | ThreadLocal<DateFormat> 或 DateTimeFormatter |
Executors.newFixedThreadPool() | new ThreadPoolExecutor(...) |
foreach 中 list.remove() | iterator.remove() |
catch(Exception e) { } | 处理异常或上抛 |
finally { return x; } | 不在 finally 中 return |
SELECT * | 明确列出字段 |
MyBatis ${param} | #{param} |
| 魔法值直接写 | 定义为常量 |
POJO boolean isDeleted | Boolean deleted (POJO 不用 is 前缀) |
long a = 2l | long a = 2L (大写 L) |
完整规约来源: D:\ai\Java开发手册(嵩山版).md
| 文件 | 内容 |
|---|---|
| references/naming.md | 命名风格(19 条) |
| references/constants.md | 常量定义(5 条) |
| references/code-format.md | 代码格式(13 条) |
| references/oop.md | OOP 规约(26 条) |
| references/date-time.md | 日期时间(7 条) |
| references/collections.md | 集合处理(21 条) |
| references/concurrency.md | 并发处理(19 条) |
| references/control-flow.md | 控制语句(14 条) |
| references/comments.md | 注释规约(12 条) |
| references/api-contract.md | 前后端规约(14 条) |
| references/others.md | 其他(8 条) |
| references/exceptions.md | 异常处理(13 条)+ 错误码(13 条) |
| references/logging.md | 日志规约(13 条) |
| references/unit-test.md | 单元测试(16 条) |
| references/security.md | 安全规约(9 条) |
| references/mysql-ddl.md | MySQL 建表规约(15 条) |
| references/mysql-index.md | MySQL 索引规约(11 条) |
| references/mysql-sql.md | MySQL SQL 语句(13 条) |
| references/orm.md | ORM 映射(10 条) |
| references/project-structure.md | 工程结构(20 条) |
| references/design.md | 设计规约(19 条) |
| 版本 | 日期 | 作者 | 变更 |
|---|---|---|---|
| 1.0.0 | 2026-04-29 | endcy | 初始版本,基于嵩山版(1.7.0)完整规约 |