Custom Error Messages
Learn how to add customized user-friendly messages on invalid inputs.
Customizing messages
Using the internationalization support we set up earlier, we can change the error messages to something more user-friendly, and have them translated for each language.
We can change the error message for all validation errors of a certain type (e.g., all @NotNull
violations) or we can precisely change the message for a single property on a single model attribute.
This is an example of the four options:
NotBlank=The property '{0}' should not be blank.NotBlank.email=Please enter the email address.NotBlank.java.lang.String=The string should not be empty.NotBlank.user.birthday=Please enter the birthday of the user.