java-coding-standards by affaan-m/everything-claude-code
npx skills add https://github.com/affaan-m/everything-claude-code --skill java-coding-standards适用于 Spring Boot 服务中可读、可维护的 Java(17+)代码规范。
// ✅ 类/记录类:PascalCase
public class MarketService {}
public record Money(BigDecimal amount, Currency currency) {}
// ✅ 方法/字段:camelCase
private final MarketRepository marketRepository;
public Market findBySlug(String slug) {}
// ✅ 常量:UPPER_SNAKE_CASE
private static final int MAX_PAGE_SIZE = 100;
// ✅ 优先使用记录类和 final 字段
public record MarketDto(Long id, String name, MarketStatus status) {}
public class Market {
private final Long id;
private final String name;
// 仅提供 getter,不提供 setter
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
// ✅ 从 find* 方法返回 Optional
Optional<Market> market = marketRepository.findBySlug(slug);
// ✅ 使用 map/flatMap 而非 get()
return market
.map(MarketResponse::from)
.orElseThrow(() -> new EntityNotFoundException("Market not found"));
// ✅ 使用流进行转换,保持管道简短
List<String> names = markets.stream()
.map(Market::name)
.filter(Objects::nonNull)
.toList();
// ❌ 避免复杂的嵌套流;为了清晰性优先使用循环
MarketNotFoundException)catch (Exception ex)throw new MarketNotFoundException(slug);
public <T extends Identifiable> Map<Long, T> indexById(Collection<T> items) { ... }
src/main/java/com/example/app/
config/
controller/
service/
repository/
domain/
dto/
util/
src/main/resources/
application.yml
src/test/java/... (镜像 main 结构)
private static final Logger log = LoggerFactory.getLogger(MarketService.class);
log.info("fetch_market slug={}", slug);
log.error("failed_fetch_market slug={}", slug, ex);
@Nullable;否则使用 @NonNull@NotNull、@NotBlank)请记住:保持代码意图明确、类型安全且可观察。除非证明有必要,否则优先考虑可维护性而非微优化。
每周安装量
704
代码仓库
GitHub 星标数
70.6K
首次出现
2026年2月12日
安全审计
安装于
codex628
opencode615
gemini-cli601
github-copilot589
kimi-cli566
cursor563
Standards for readable, maintainable Java (17+) code in Spring Boot services.
// ✅ Classes/Records: PascalCase
public class MarketService {}
public record Money(BigDecimal amount, Currency currency) {}
// ✅ Methods/fields: camelCase
private final MarketRepository marketRepository;
public Market findBySlug(String slug) {}
// ✅ Constants: UPPER_SNAKE_CASE
private static final int MAX_PAGE_SIZE = 100;
// ✅ 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
}
// ✅ Return Optional from find* methods
Optional<Market> market = marketRepository.findBySlug(slug);
// ✅ Map/flatMap instead of get()
return market
.map(MarketResponse::from)
.orElseThrow(() -> new EntityNotFoundException("Market not found"));
// ✅ Use streams for transformations, keep pipelines short
List<String> names = markets.stream()
.map(Market::name)
.filter(Objects::nonNull)
.toList();
// ❌ Avoid complex nested streams; prefer loops for clarity
Use unchecked exceptions for domain errors; wrap technical exceptions with context
Create domain-specific exceptions (e.g., MarketNotFoundException)
Avoid broad catch (Exception ex) unless rethrowing/logging centrally
throw new MarketNotFoundException(slug);
Avoid raw types; declare generic parameters
Prefer bounded generics for reusable utilities
public <T extends Identifiable> Map<Long, T> indexById(Collection<T> items) { ... }
src/main/java/com/example/app/
config/
controller/
service/
repository/
domain/
dto/
util/
src/main/resources/
application.yml
src/test/java/... (mirrors main)
private static final Logger log = LoggerFactory.getLogger(MarketService.class);
log.info("fetch_market slug={}", slug);
log.error("failed_fetch_market slug={}", slug, ex);
@Nullable only when unavoidable; otherwise use @NonNull@NotNull, @NotBlank) on inputsRemember : Keep code intentional, typed, and observable. Optimize for maintainability over micro-optimizations unless proven necessary.
Weekly Installs
704
Repository
GitHub Stars
70.6K
First Seen
Feb 12, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex628
opencode615
gemini-cli601
github-copilot589
kimi-cli566
cursor563
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装