affaan-m/ECC

java-coding-standards

Spring Boot服务的Java编码标准:命名、不可变性、Optional用法、流、异常、泛型和项目布局。

72Collecting
See how to use itView GitHub source
npx skills add https://github.com/affaan-m/ECC --skill "docs/zh-CN/skills/java-coding-standards"
Automated source guide

Source checked Jul 28, 2026·Refresh due Oct 26, 2026

Reorganized from the pinned upstream SKILL.md

Turn java-coding-standards's source instructions into a guide you can follow

According to the pinned SKILL.md from affaan-m/ECC: 适用于 Spring Boot 服务中可读、可维护的 Java (17+) 代码的规范。

npx skills add https://github.com/affaan-m/ECC --skill "docs/zh-CN/skills/java-coding-standards"
Check the pinned source

Best fit

  • Spring Boot服务的Java编码标准:命名、不可变性、Optional用法、流、异常、泛型和项目布局。

Bring this context

  • A concrete task that matches the documented purpose of java-coding-standards.
  • The files, examples, or context the task depends on.
  • Your constraints, target environment, and definition of done.

Expected outputs

  • A result that follows the pinned java-coding-standards instructions.
  • A concise record of assumptions, inputs used, and unresolved questions.
  • A final check against the source workflow and relevant permission signals.

Key source sections

Read java-coding-standards through these 5 source sections

Sections are extracted automatically from the pinned SKILL.md and link back to the source.

01

何时激活

在 Spring Boot 项目中编写或审查 Java 代码时 强制执行命名、不可变性或异常处理约定时 使用记录类、密封类或模式匹配(Java 17+)时 审查 Optional、流或泛型的使用时 构建包和项目布局时

SKILL.md · 何时激活
在 Spring Boot 项目中编写或审查 Java 代码时强制执行命名、不可变性或异常处理约定时使用记录类、密封类或模式匹配(Java 17+)时
02

核心原则

清晰优于巧妙 默认不可变;最小化共享可变状态 快速失败并提供有意义的异常 一致的命名和包结构

SKILL.md · 核心原则
清晰优于巧妙默认不可变;最小化共享可变状态快速失败并提供有意义的异常
03

命名

Review the “命名” section in the pinned source before continuing.

SKILL.md · 命名
Review and apply the “命名” source section.
04

不可变性

Review the “不可变性” section in the pinned source before continuing.

SKILL.md · 不可变性
Review and apply the “不可变性” source section.
05

Optional 使用

Review the “Optional 使用” section in the pinned source before continuing.

SKILL.md · Optional 使用
Review and apply the “Optional 使用” source section.

SkillSignal prompt templates

Provide the task, context, and acceptance criteria

These prompts were written by SkillSignal from the source structure; they are not upstream text.

Task-start prompt

Confirm source fit, inputs, and outputs before acting.

Use java-coding-standards to help me with: [specific task]. Context: [files, data, or background]. Constraints: [environment, scope, and prohibited actions]. Before acting, check the pinned SKILL.md and explain which sections apply, what inputs are still missing, and what you will deliver.

Source-guided execution

Make the Agent explicitly follow the key extracted sections.

Apply the pinned java-coding-standards source to [task]. Pay particular attention to these source sections: “何时激活”, “核心原则”, “命名”, “不可变性”, “Optional 使用”. Preserve the important decision at each step. Mark facts not covered by the source as “needs confirmation” instead of inventing them. Then verify the result against my acceptance criteria: [criteria].

Result-review prompt

Check omissions, permissions, and source drift before delivery.

Review the current java-coding-standards result: (1) does it satisfy the original task; (2) were any applicable steps or limits in the pinned SKILL.md missed; (3) did it perform any unauthorized file, command, network, or data action; and (4) which conclusions remain unverified? List issues first, then fix only what the source or user authorization supports.

Output checklist

Verify each item before delivery

The task matches the purpose documented in the SKILL.md.

The source section “何时激活” has been checked.

The source section “核心原则” has been checked.

The source section “命名” has been checked.

The source section “不可变性” has been checked.

Inputs, constraints, and acceptance criteria are explicit.

Unverified facts, compatibility, and outcome claims are clearly marked.

Any file, command, network, or data action has been reviewed.

Choose a different workflow

When another Skill is the better fit

FAQ

What does java-coding-standards do?

适用于 Spring Boot 服务中可读、可维护的 Java (17+) 代码的规范。

How do I start using java-coding-standards?

The catalog detected this source-specific install command: npx skills add https://github.com/affaan-m/ECC --skill "docs/zh-CN/skills/java-coding-standards". Inspect the command and pinned source before running it.

Which Agent platforms does it declare?

No dedicated Agent platform is declared in the pinned source record.

Repository stars
234,327
Repository forks
35,711
Quality
72/100
Source repository last pushed

Quality breakdown

Based on traceable docs and repository signals; stars are not treated as quality.

72/100
Documentation24/30
Specificity11/25
Maintenance20/20
Trust signals17/25

Compare before choosing

Related Agent Skills and source variants

These links are selected from shared tasks, functions, stacks, platforms, and same-name variants. Compare the source owner, documentation, permissions, and maintenance signals.

View original Skill.mdThis page is parsed directly from the repository SKILL.md without editorial rewriting. Collected: Jul 28, 2026 · about 1 min

Java 编码规范

适用于 Spring Boot 服务中可读、可维护的 Java (17+) 代码的规范。

何时激活

  • 在 Spring Boot 项目中编写或审查 Java 代码时
  • 强制执行命名、不可变性或异常处理约定时
  • 使用记录类、密封类或模式匹配(Java 17+)时
  • 审查 Optional、流或泛型的使用时
  • 构建包和项目布局时

核心原则

  • 清晰优于巧妙
  • 默认不可变;最小化共享可变状态
  • 快速失败并提供有意义的异常
  • 一致的命名和包结构

命名

// PASS: Classes/Records: PascalCase
public class MarketService {}
public record Money(BigDecimal amount, Currency currency) {}

// PASS: Methods/fields: camelCase
private final MarketRepository marketRepository;
public Market findBySlug(String slug) {}

// PASS: Constants: UPPER_SNAKE_CASE
private static final int MAX_PAGE_SIZE = 100;

不可变性

// PASS: Favor records and final fields
public record MarketDto(Long id, String name, MarketStatus status) {}

public class Market {
  private final Long id;
  private final String name;
  // getters only, no setters
}

Optional 使用

// PASS: Return Optional from find* methods
Optional<Market> market = marketRepository.findBySlug(slug);

// PASS: Map/flatMap instead of get()
return market
    .map(MarketResponse::from)
    .orElseThrow(() -> new EntityNotFoundException("Market not found"));

Streams 最佳实践

// PASS: Use streams for transformations, keep pipelines short
List<String> names = markets.stream()
    .map(Market::name)
    .filter(Objects::nonNull)
    .toList();

// FAIL: Avoid complex nested streams; prefer loops for clarity

异常

  • 领域错误使用非受检异常;包装技术异常时提供上下文
  • 创建特定领域的异常(例如,MarketNotFoundException
  • 避免宽泛的 catch (Exception ex),除非在中心位置重新抛出/记录
throw new MarketNotFoundException(slug);

泛型和类型安全

  • 避免原始类型;声明泛型参数
  • 对于可复用的工具类,优先使用有界泛型
public <T extends Identifiable> Map<Long, T> indexById(Collection<T> items) { ... }

项目结构 (Maven/Gradle)

src/main/java/com/example/app/
  config/
  controller/
  service/
  repository/
  domain/
  dto/
  util/
src/main/resources/
  application.yml
src/test/java/... (mirrors main)

格式化和风格

  • 一致地使用 2 或 4 个空格(项目标准)
  • 每个文件一个公共顶级类型
  • 保持方法简短且专注;提取辅助方法
  • 成员顺序:常量、字段、构造函数、公共方法、受保护方法、私有方法

需要避免的代码坏味道

  • 长参数列表 → 使用 DTO/构建器
  • 深度嵌套 → 提前返回
  • 魔法数字 → 命名常量
  • 静态可变状态 → 优先使用依赖注入
  • 静默捕获块 → 记录日志并处理或重新抛出

日志记录

private static final Logger log = LoggerFactory.getLogger(MarketService.class);
log.info("fetch_market slug={}", slug);
log.error("failed_fetch_market slug={}", slug, ex);

Null 处理

  • 仅在不可避免时接受 @Nullable;否则使用 @NonNull
  • 在输入上使用 Bean 验证(@NotNull, @NotBlank

测试期望

  • 使用 JUnit 5 + AssertJ 进行流畅的断言
  • 使用 Mockito 进行模拟;尽可能避免部分模拟
  • 倾向于确定性测试;没有隐藏的休眠

记住:保持代码意图明确、类型安全且可观察。除非证明有必要,否则优先考虑可维护性而非微优化。

Source repo
affaan-m/ECC
Skill path
docs/zh-CN/skills/java-coding-standards/SKILL.md
Commit SHA
4e973d3eaf92
Repository license
MIT
Data collected