-Last time (Java version), Last time (Kotlin version) --Create a simple CRUD app with Spring Boot --This time, customize the message when a validation error occurs. --Currently, there is an English message prepared by default.
--Create a configuration file and define a message
--If you create a message definition with the file name ValidationMessage.properties
, Spring will use this content without permission.
--Create ValidationMessages.properties
in src / main / resources
src/main/resources/ValidationMessages.properties
org.hibernate.validator.constraints.NotEmpty.message=Required fields
javax.validation.constraints.NotNull.message=Required fields
javax.validation.constraints.Max.message={value}Please do the following
javax.validation.constraints.Min.message={value}Please do above
javax.validation.constraints.Size.message={min}More than letters{max}Please make it less than a letter
--If you enter Japanese as it is in Eclipse, the characters may be garbled when the screen is displayed. --In such a case, you can solve it by inserting a plug-in called Property Editor.
--Here is the list of default error messages - https://github.com/hibernate/hibernate-validator/blob/master/engine/src/main/resources/org/hibernate/validator/ValidationMessages.properties
--Such an image when applied successfully
--Next time here
Recommended Posts