springMVC data check using JSR303

JSR303 Annotations

 

 hibernate validate jsr is a reference implementation of 303, in addition to support for all standard check notes, he also supports extended comment

 

 spring4.0 has its own independent data validation framework, while supporting jsr 303 standard validation framework.

When binding data during spring, the work can be done by calling the data check validation framework. In springMVC, the check data can be directly driven by way of annotation.

spring of localvalidatorFactoryBean only to achieve the spring of validator interface also implements the interface to validate the jsr 303. As long as the spring defines a LocalValidateFactoryBean vessel, it can be injected to the desired data verification bean.

spring itself does not provide jsr 303 is implemented, it must be achieved by a jar jsr 303 under the package in the class path.

Add hibernate validator maven dependencies in the configuration file.

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.4.1.Final</version>
</dependency>
                

<Mvc: annotation-driven> </ mvc: annotation> a default assembled LocalValidateFactoryBean, denoted by reference @Valid annotation on the processing method of the data to make the implementation springMVC check data after completion of the binding.

On Bean annotated

 

 By labeling approach @Valid annotation on the control layer to make reference springMVC implementation data after the data verification binding.

 

 Sending a request through the REST Client

 

 The results show an empty field does not include the ID number, phone number, name of.

 

Guess you like

Origin www.cnblogs.com/liu1275271818/p/11734421.html