适用于 Spring Boot 服务的 Java 编码规范:命名、不可变性、Optional 使用、流(Stream)、异常、泛型及项目布局。
64
76%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./docs/ja-JP/skills/java-coding-standards/SKILL.md适用于 Spring Boot 服务中易读且可维护的 Java (17+) 代码标准。
// ✅ 类/记录(Record): 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;// ✅ 优先使用 record 和 final 字段
public record MarketDto(Long id, String name, MarketStatus status) {}
public class Market {
private final Long id;
private final String name;
// 仅有 getter,没有 setter
}// ✅ find* 方法返回 Optional
Optional<Market> market = marketRepository.findBySlug(slug);
// ✅ 使用 map/flatMap 代替 get()
return market
.map(MarketResponse::from)
.orElseThrow(() -> new EntityNotFoundException("Market not found"));// ✅ 使用流进行转换,保持流水线(Pipeline)简洁
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)sleep记住:保持代码的意图清晰、类型安全且可观测。除非证明确有必要,否则应优先优化可维护性而非微小的性能优化。
dfbf946
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.