Using the message attribute

Each of the annotations used in the bean class to validate the data has the message attribute. The developers can use it to pass the appropriate message, as shown in the following code:

public class Book { 
  @NotEmpty(message="The book name should be entered") 
  privateStringbookName; 
 
  @Min(value=150,message="ISBN should be greater than 150") 
  privatelong ISBN; 
 
  @Size(min = 2, max = 30, message="Enter Publication between   
  limit of 2 to 30 only") 
  private String publication; 
 
  @NotNull(message="Enter the price") 
  private int price; 
  @Size(min = 10, max = 50,message="Enter Publication between limit of
10 to 50 only") private String description; @NotEmpty(message="Enter the price") private String author; //default and parameterized constructor //getters and setters }

Keeping all other code as it is, and changing the code of the Book.java file as shown in the preceding code, run the application. If any violation of the validation rule occurs, the messages configured for the message attribute will be displayed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.10.246