본문 바로가기

Develop/Backend 가이드

[Spring] @NotNull, @NotEmpty, @NotBlank 차이

반응형

JPA and Hibernate
JPA / Hibernate

결론

String text 값에 따라 @Notnull / @NotEmpty / @NotBlank 결과가 어떻게 달라지는지 표로 정리했습니다.

String text = null;
AnnotationBoolean
@NotNullfalse
@NotEmptyfalse
@NotBlankfalse
String text = "";
AnnotationBoolean
@NotNulltrue
@NotEmptyfalse
@NotBlankfalse
String text = " ";
AnnotationBoolean
@NotNulltrue
@NotEmptytrue
@NotBlankfalse
String text = "Hello, World!";
AnnotationBoolean
@NotNulltrue
@NotEmptytrue
@NotBlanktrue

@NotEmpty

@NotNull 에서 확장하여 null 이 아니고 크기가 1 이상인지 확인합니다.

@NotNull  
@Size(min = 1)

@NotBlank

@NotEmpty 에서 확장하여 null 이 아니고 단순한 띄어쓰기가 아닌지 확인합니다.

@NotNull  
@Constraint(validatedBy = {NotBlankValidator.class})
반응형

'Develop > Backend 가이드' 카테고리의 다른 글