Open utterances-bot opened 3 years ago
String같은경우는 Null과 Empty String도 확인할 수 있는 @NotBlank를 사용해도 좋아보이네요~!
알아보니, @NotEmpty가 null과 Empty String을 체크해주는데요. NotBlank는 " "같은 빈 문자열도 잡아줄 수 있다고 하네요.
@knb1109 님이 좋은 얘기해주셨네요.
실제로 @NotBlank = 문자열 @NotEmpty = collection @NotNull = 객체 (저는 보통 LocalDate 때 사용합니다.)
로 보시면 됩니다. 그리고 팁으로
@Email(message = "올바르지 않은 이메일형식입니다: ${validatedValue}")
이런식으로 작성시 입력값을 알수 있습니다.
그리고 private static Validator validator; 이렇게 사용을 할수도 있지만 @Validated 를 사용하면
@Validated @Service public class AService {
public List<B> getList(@Valid Dto b) {
이런식으로 작성하면 validation 이 작동됩니다.
좋은 의견 감사합니다!!!
Spring Boot에서 DTO 검증하기 | javable
검증이 왜 필요할까?
https://woowacourse.github.io/tecoble/post/2020-09-20-validation-in-spring-boot/