Custom Error Messages
Learn how to add customized user-friendly messages on invalid inputs.
We'll cover the following...
We'll cover the following...
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:
Press + to interact
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.