Spring REST Validation Example

In this article, we will enhance the previous Spring REST Hello World example, by adding bean validation and custom validator. Technologies used : Spring Boot 2.1.2.RELEASE Spring 5.1.4.RELEASE Maven 3 Java 8 1. Controller Review the previous REST Controller again : BookController.java package com.mkyong; import com.mkyong.error.BookNotFoundException; import com.mkyong.error.BookUnSupportedFieldPatchException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import …

Read more

Combine Spring validator and Hibernate validator

In this article, we will show you how to validate the submitted form values with Spring validator and Hibernate Validator (bean validation). Technologies used : Spring 4.1.6.RELEASE Hibernate Validator 5.1.3.Final 1. Hibernate Validator The Hibernate validator will be fired if @Valid is provided. import org.hibernate.validator.constraints.NotEmpty; public class User { @NotEmpty String name; //… } @RequestMapping(value …

Read more