Simple validations on the bean

The Bean Validation API specifies a number of validations that can be specified on attributes on the beans. Take a look at the following listing:

   @Size(min = 6, message = "Enter at least 6 characters")    private String name;    @Size(min = 6, message = "Enter at least 6 characters")    private String userId;    @Size(min = 8, message = "Enter at least 8 characters")    private String password;    @Size(min = 8, message = "Enter at least 8 characters")    private String password2;

An important thing to note are as follows:

  • @Size(min = 6, message = "Enter at least 6 characters") : This specifies that the field should at least have six characters. If the validation does not pass, the text from the message attribute is used ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.