/claude-dx:java-coding-standardsfrom claude-dx
Java 编码规范(Spring Boot 服务):命名、OOP、不可变性、集合、并发、异常、日志、Spring Boot 分层、MySQL。基于阿里巴巴 Java 开发手册。
Ships in claude-dx. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
适用于 Spring Boot 服务的 Java(17+)编码规范,基于阿里巴巴 Java 开发手册。
UserDTO、OrderVO)Abstract 或 Base 开头,异常类以 Exception 结尾,测试类以被测类名 + Test 结尾Enum 后缀,成员名全大写,下划线分隔public class MarketService {}
public record Money(BigDecimal amount, Currency currency) {}
private final MarketRepository marketRepository;
public Market findBySlug(String slug) {}
private static final int MAX_PAGE_SIZE = 100;
@Override 注解Object 的 equals 方法容易 NPE,应使用常量或确定非空的对象调用 equalsequals 方法,禁止用 ==init 方法中toString 方法public record MarketDto(Long id, String name, MarketStatus status) {}
public class Market {
private final Long id;
private final String name;
}
Map 的 entrySet 遍历而非 keySet(后者多一次查询)foreach 循环中对集合进行 add/remove,使用 Iterator 或 removeIftoArray(new String[0]),禁止使用无参 toArray()Arrays.asList() 返回的是不可修改列表,不能执行 add/removeArrayList 的 subList 返回的是内部类,不可强转为 ArrayList,对子列表的修改会影响原列表Map<String, Object> map = new HashMap<>(16);
List<String> list = new ArrayList<>(expectedSize);
List<String> names = markets.stream()
.map(Market::name)
.filter(Objects::nonNull)
.toList();
Optional<Market> market = marketRepository.findBySlug(slug);
return market
.map(MarketResponse::from)
.orElseThrow(() -> new EntityNotFoundException("Market not found"));
public <T extends Identifiable> Map<Long, T> indexById(Collection<T> items) { ... }
Executors 创建,必须通过 ThreadPoolExecutor 显式指定参数SimpleDateFormat 线程不安全,禁止定义为 static 变量;推荐使用 DateTimeFormatterThreadPoolExecutor executor = new ThreadPoolExecutor(
corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(queueCapacity),
new ThreadFactoryBuilder().setNameFormat("biz-pool-%d").build(),
new ThreadPoolExecutor.CallerRunsPolicy()
);
MarketNotFoundException)catch (Exception ex),除非是统一日志/重抛的场景throw new MarketNotFoundException(slug);
if/else/for/while/do 语句必须使用大括号,即使只有一行switch 语句的每个 case 要么通过 break/return 终止,要么注释说明 fallthroughswitch 必须包含 default 分支@Nullable,其他情况使用 @NonNull@NotNull、@NotBlank)校验private static final Logger log = LoggerFactory.getLogger(MarketService.class);
log.info("fetch_market slug={}", slug);
log.error("failed_fetch_market slug={}", slug, ex);
/** */),禁止使用 // 替代//,放在被注释语句的上方,与代码对齐@Deprecated 的方法必须注释说明替代方案@Transactional 注解仅加在需要事务的方法上,避免大事务;只读查询使用 @Transactional(readOnly = true)@ConfigurationProperties 绑定,禁止散落的 @Valuecode、message、data 字段@Valid + Bean Validation 注解校验@Data
public class ApiResponse<T> {
private int code;
private String message;
private T data;
}
@PostMapping("/users")
public ApiResponse<UserVO> createUser(@Valid @RequestBody CreateUserRequest request) {
return ApiResponse.success(userService.createUser(request));
}
核心理念:代码应当意图明确、类型安全、可观测。优先优化可维护性,除非有性能瓶颈的实证,否则不做微优化。
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub wsong001/claude-dx --plugin claude-dx6 skills in this plugin
/setup