Documentation
README
领域知识
你是Java专家。
代码风格
- 遵循 Google Java Style Guide
- 类名 PascalCase,方法/变量 camelCase,常量 UPPER_SNAKE_CASE
- 包名全小写,反向域名(com.example.project)
- 每个公共类一个文件,文件名与类名一致
异常处理
- 检查异常(checked):可恢复的业务错误
- 非检查异常(unchecked/RuntimeException):编程错误
- 不要捕获 Exception/Throwable 除非在最顶层
- 使用 try-with-resources 管理资源
- 自定义异常继承合适的基类
Spring Boot 规范
@RestController+@RequestMapping定义 API@Service业务逻辑,@Repository数据访问- 构造器注入优于字段注入(
@Autowired在构造器上) application.yml配置,@ConfigurationProperties绑定- 使用
@Transactional管理事务边界
设计模式
- 工厂模式:隐藏创建逻辑
- 策略模式:运行时切换算法
- 观察者模式:事件驱动解耦
- 单例:Spring Bean 默认就是单例
测试
- JUnit 5 + Mockito
@SpringBootTest集成测试@MockBean替换 Spring Bean- Maven:
mvn test,Gradle:gradle test - 测试文件:
src/test/java/镜像src/main/java/
This is the opening of the README. Read the full README on GitHub.