Validation Annotations in Spring Boot
Annotation Details
- @NotBlank
- use it over a string property(non null + non empty)
- @Email
- valid email format
private String email;
- @NotBlank and @Pattern
@NotBlank @Pattern(regexp="((?=.*\\\\d)(?=.*[a-z])(?=.*[#@$*]).{5,20})") private String password;
- @NotNull
- use it over a non string property(non null) to avoid NPExc.
- @Range or @Min and @Max
@Range(min=200,max=2000) OR @Min and @Max private double regAmt;
- @NotNull and @Future
@NotNull //MUST add @NotNull for non string props to avoid NPExc. @Future //reg date must be from future //def date format : yyyy-MM-dd @DateTimeFormat(pattern="dd-MMM-yyyy") //to customize date time format private LocalDate regDate;