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中的实现

  1. @Component
  2. @ConfigurationProperties(prefix="person")
  3. @Validate //enable back-end verification
  4. {
  5. @Email()
  6. private Sting email;
  7. private String name;
  8. }

yaml file

  1. person:
  2. email: xxxx
  3. name: lfg

test

  1. public class test
  2. {
  3. @Autowired
  4. private Person person;
  5. System.out.println(person);
  6. }

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