Create a simple CRUD with SpringBoot + JPA + Thymeleaf ④ ~ Customize error messages ~

Contents

-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.

スクリーンショット 2017-10-26 0.31.02.png

procedure

--Create a configuration file and define a message

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.

スクリーンショット 2017-10-26 0.39.48.png

--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

Operation check

--Such an image when applied successfully

スクリーンショット 2017-10-26 0.47.39.png スクリーンショット 2017-10-26 0.47.57.png

next time

--Next time here

Recommended Posts

Create a simple CRUD with SpringBoot + JPA + Thymeleaf ④ ~ Customize error messages ~
Create a simple CRUD with SpringBoot + JPA + Thymeleaf ③ ~ Add Validation ~
Create a simple CRUD with SpringBoot + JPA + Thymeleaf ② ~ Screen and function creation ~
Make a simple CRUD with SpringBoot + JPA + Thymeleaf ① ~ Hello World ~
Make a simple CRUD with SpringBoot + JPA + Thymeleaf ⑤ ~ Template standardization ~
Create a simple DRUD application with Java + SpringBoot + Gradle + thymeleaf (1)
Create a simple web application with Dropwizard
Create a simple on-demand batch with Spring Batch
[Rails withdrawal] Create a simple withdrawal function with rails
Create a simple bar chart with MPAndroidChart
Create a simple search app with Spring Boot
Create a simple bulletin board with Java + MySQL
04. I made a front end with SpringBoot + Thymeleaf
Create CRUD apps with Spring Boot 2 + Thymeleaf + MyBatis
Show a simple Hello World with SpringBoot + IntelliJ
A simple CRUD app made with Nuxt / Laravel (Docker)
Create a simple demo site with Spring Security with Spring Boot 2.1
I wrote a CRUD test with SpringBoot + MyBatis + DBUnit (Part 1)
Create a playground with Xcode 12
Draw screen with Thymeleaf in SpringBoot
Create a Vue3 environment with Docker!
Implement text link with Springboot + Thymeleaf
Create exceptions with a fluid interface
Create a Maven project with a command
Create a simple gateway server by setting masquerade with firewall-cmd of CentOS8