- 后端校验在SpringBoot中的实现
- JSR303提供的注解
- @Null(message=”this value must be null”)
- @NotNull(message=”this value should’t be null”)
- @Max(value=100,message=”this value should be less than 100”)
- @Min(value=100,message=”this value should be greater than 100”)
- @AssertTrue(message=”this value must be true”)
- @AssertFalse(message=”this value must be false”)
- @Past(message=”this time is not past,it’s future”)
- @Future(message=”this time is not futrue , it’s before than currrrent”)
In HTML, a input tag can be appointed type,for example ,this input area can be inputed string which is accord with format of email;we call this limit front-end verification ;of course,verification can be finished not only at front-end;
if no type is appointed by input tag;this input message need checked in back-end;
后端校验在SpringBoot中的实现
@Component@ConfigurationProperties(prefix="person")@Validate //enable back-end verification{@Email()private Sting email;private String name;}
yaml file
person:email: xxxxname: lfg
test
public class test{@Autowiredprivate Person person;System.out.println(person);}
if run this program;program will throw a error tell you “xxx is not a email”
JSR303提供的注解
@Null(message=”this value must be null”)
this annotation will check weather the property is null;(require property is null to pass check),if property’s value is Notnull; program will throw error with message;
@NotNull(message=”this value should’t be null”)
require property is not null to pass check;if value is null ,progam will throw error with message
@Max(value=100,message=”this value should be less than 100”)
this annotation ask property’s max value less than 100;
@Min(value=100,message=”this value should be greater than 100”)
this annotation ask property’s min value greater than 100;
@AssertTrue(message=”this value must be true”)
this annotaton saks property’s value must be “true”;
@AssertFalse(message=”this value must be false”)
this annotation saks property’s value must be false;
@Past(message=”this time is not past,it’s future”)
this annotation asks time value is past ranther than a value after current
@Future(message=”this time is not futrue , it’s before than currrrent”)
this annotation require this value is befoe than current
