Title
SpringBoot - > @Valid 를 이용한 @RequestBody 객체 검증하기
Issue
RestController에서 Request DTO의 데이터를 검증하기 위해
검증하고 자하는 body의 @RequestBody 앞에 @Valid을 붙여준다.
→ Service 단이 아닌 컨트롤러 단 진입 Request DTO 에서 NULL체크 및 유효성 검증을 할수 있다.
implementation 'org.springframework.boot:spring-boot-starter-validation'
@Valid 어노테이션 종류 : @Vaild annotation Type Link
- @Vaild 를 사용할 때는 검증하고자 하는 DTO 각 객체의 형식에 알맞는 annotation 을 사용해야한다.
Reference
'Spring' 카테고리의 다른 글
| [Spring] Servlet Filter 사용하기 (0) | 2023.05.29 |
|---|---|
| [Spring] AOP (Aspect-Oriented Programming) 란? AOP로 로깅하기 (0) | 2023.04.12 |
| [Spring] @Builder + @NoArgsConstructor 사용 시 발생하는 이슈 (0) | 2023.03.27 |
| [Spring] 실무에서 Logger를 사용하는 이유 (0) | 2023.02.05 |
| [Spring ] UUID, PK 로 사용하기 (1) | 2023.01.30 |