[Spring] @Valid Annotation
Entity
애노테이션을 사용하면 쉽게 Entity에 대한 유효성 검사를 할 수 있다. 해당 애노테이션은 javax.validation.constraints패키지에 정의되어 있으며, 이를 아래와 같이 활용할 수 있다.
public class Member { private Long idx; "name null") (message= private String name; 14, message="min 14") (value= private Integer age; "tel null") (message= private String tel; } |
@NotNull
: null 검증@Min
, @Max
: 최소값, 최대값 검증@Size
: 범위 검증@Email
: e-mail 검증@AssertTrue
: true 검증@NotEmpty
: null이나 size가 0 검증 (String, Collection)@NotBlank
: null이나 whitespace 검증 (String)@Positive
, @PositiveOrZero
: 숫자 검증@Negative
, @NegativeOrZero
: 숫자 검증@Past
, @PastOrPresent
: 날짜 검증@Future
, @FutureOrPresent
: 날짜 검증
댓글
댓글 쓰기