Validation(검증)
public class Example {
@NotNull
@Min(0)
Integer example;
}public class Example {
@PostMapping("/example")
public String example(@Valid @ModelAttribute Example example, BindingResult bindingResult) {
// ...
return "example";
}
}@Valid 동작 원리
ModelAttribute 바인딩(@ModelAttribute)
요청 본문 바인딩(@RequestBody)와 메시지 컨버터
검증 대상과 바인딩 소스 요약
구분
바인딩 소스
검증 시점
예외 처리
@Validated
그룹 검증
동작 원리(클래스 레벨에 선언한 경우)
오류 처리 패턴
@Valid vs @Validated
@Valid
@Validated
Last updated