303-frameworks-spring-boot-validation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Spring Boot Validation Guidelines

Spring Boot 验证指南

Apply Spring Boot validation best practices at API boundaries.
What is covered in this Skill?
  • Bean Validation annotations on DTOs and command models
  • @Valid / @Validated on controllers and method parameters
  • Validation groups for create/update workflows
  • Custom constraint annotations and validators
  • Consistent 400 error responses for validation failures
Scope: Apply recommendations based on the reference rules and good/bad examples.
在API边界处应用Spring Boot验证最佳实践。
本技能涵盖哪些内容?
  • DTO和命令模型上的Bean Validation注解
  • 控制器和方法参数上的@Valid / @Validated注解
  • 用于创建/更新流程的验证组
  • 自定义约束注解与验证器
  • 验证失败时返回一致的400错误响应
范围: 根据参考规则和优劣示例应用建议。

Constraints

约束条件

Before applying validation changes, ensure the project compiles. After improvements, run full verification.
  • MANDATORY: Run
    ./mvnw compile
    or
    mvn compile
    before applying any change
  • SAFETY: If compilation fails, stop immediately
  • VERIFY: Run
    ./mvnw clean verify
    or
    mvn clean verify
    after applying improvements
  • BEFORE APPLYING: Read the reference for detailed rules and examples
在应用验证更改前,确保项目可编译。完成改进后,执行完整验证。
  • 强制要求:在进行任何更改前运行
    ./mvnw compile
    mvn compile
  • 安全提示:如果编译失败,立即停止操作
  • 验证步骤:完成改进后运行
    ./mvnw clean verify
    mvn clean verify
  • 应用前须知:阅读参考文档了解详细规则和示例

When to use this skill

何时使用本技能

  • Add validation support in Spring Boot
  • Review Spring Boot validation rules
  • Improve request validation in Spring Boot REST APIs
  • Add custom Bean Validation constraints in Spring Boot
  • Validate configuration properties in Spring Boot
  • Improve nested DTO validation in Spring Boot
  • 在Spring Boot中添加验证支持
  • 审查Spring Boot验证规则
  • 改进Spring Boot REST API的请求验证
  • 在Spring Boot中添加自定义Bean Validation约束
  • 验证Spring Boot配置属性
  • 改进Spring Boot中的嵌套DTO验证

Workflow

工作流程

  1. Read reference and assess project context
Read
references/303-frameworks-spring-boot-validation.md
and inspect the current project setup before proposing changes.
  1. Gather scope and decide target improvements
Identify requested outcomes, constraints, and the minimum safe set of changes to apply.
  1. Apply framework-aligned changes
Implement or refactor validation-related configuration/code following the reference patterns and project conventions.
  1. Run verification and report results
Execute appropriate build/tests and summarize what changed, what was verified, and any follow-up actions.
  1. 阅读参考文档并评估项目背景
在提出更改前,阅读
references/303-frameworks-spring-boot-validation.md
并检查当前项目配置。
  1. 确定范围并制定目标改进方案
明确预期结果、约束条件,以及可安全应用的最小更改集。
  1. 遵循框架规范进行更改
按照参考模式和项目约定,实现或重构验证相关的配置/代码。
  1. 执行验证并报告结果
执行相应的构建/测试,总结更改内容、验证情况以及后续行动建议。

Reference

参考文档

For detailed guidance, examples, and constraints, see references/303-frameworks-spring-boot-validation.md.
如需详细指导、示例和约束说明,请查看references/303-frameworks-spring-boot-validation.md