Java common standards

From jie023/trae-setting · View interactive version

Java common standards is an AI agent skill from the GitHub repository jie023/trae-setting. Provides common Java coding standards including hutool tool usage and Lombok annotations. Invoke when generating Java code (DO, VO, Service, Controller) or applying coding standards.

How to use this skill

Skill file

Java通用编码规范

本技能提供Java通用编码规范,包括工具类使用规范和Lombok注解使用规范,适用于所有Java类的生成。

Java工具类使用规范 *** 强制执行 ***

hutool工具类优先使用

hutool常用工具类

使用示例

// 字符串判空
if (StrUtil.isNotBlank(str)) {
    // 处理逻辑
}

// 日期格式化
String dateStr = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss");

// 集合判空
if (CollUtil.isNotEmpty(list)) {
    // 处理逻辑
}

// 对象属性拷贝
BeanUtil.copyProperties(source, target);

Lombok注解使用规范 *** 强制执行 ***

Lombok注解优先使用

常用注解

注解使用示例

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

// 使用@Data注解(推荐)
@Data
@ToString
public class UserVO {
    private String userId;
    private String userName;
}

// 单独使用注解
@Getter
@Setter
@ToString
public class UserVO {
    private String userId;
    private String userName;
}

注意事项

最佳实践

  1. 工具类选择:优先使用hutool工具类,其次考虑Apache Commons、Guava等
  2. 注解使用:合理使用Lombok注解,避免过度使用
  3. 代码简洁:减少样板代码,提高代码可读性
  4. 性能考虑:选择性能最优的工具类方法
  5. 异常处理:使用工具类时注意异常处理机制

适用范围

本规范适用于以下Java类的生成:

调用时机

在以下情况下调用本技能:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.