@Min And @Max Javax Validation Hibernate Example

In this post, we will see @Min And @Max Javax Validation Hibernate Example Using Spring Boot.

@Min And @Max Javax Validation Hibernate Example
If we have valid request data.

 

Invalid Request

 


 

Let’s see @Min And @Max Javax Validation Hibernate Example from scratch. After running below example, we will be able to save an entity in the database if we have valid request data else it will show the validation error message.

Valid Request Data –

@Min And @Max Javax Validation

Invalid request data –

 

Open eclipse and create maven project, Don’t forget to check ‘Create a simple project (skip)’ click on next.  Fill all details as below and click on finish.

Hibernate Validator Spring Boot

 

Modify pom.xml

Note – In pom.xml we have defined javac.exe path in configuration tag. You need to change accordingly i.e where you have installed JDK.

If you see any error for oracle dependency then follow these steps.

Directory structure –

Hibernate Validator Example

 

Student.java

StudentController.java

StudentRepository.java – interface

StudentService.java – interface

 

StudentServiceImpl.java

 

GlobalErrorHandler.java – Let’s define a error handler class. This class will be used when validateEntity() method will throw ConstraintViolationException(See more details about GlobalErrorHandler here).

 

ResponseError.java

SpringMain.java

 

JpaConfig.java

application.properties

Let’s run the SpringMain class(run as java application).

 

 

That’s all about @Min And @Max Javax Validation Hibernate Example Using Spring Boot.

You May like.

Spring Data JPA Docs.

Top