SPRINGMVC Data validation

Source: Internet
Author: User

1. Introduction of the JAR package

Com.springsource.javax.validation-1.0.0.ga.jar specification (just definition)

Hibernate-validator-4.1.0.final.jar Vendor Implementation

Log4j.jar

Slf4j-api-1.5.8.jar

Slf4j-log4j12.jar

2. Validation feature to add validation annotations on entity classes

1 Person.java 2 @Size (min=3,max=10,message= "user name must be greater than 3 characters, less than 10 characters") 3 private String name; 4 @NotNull (message= "Age cannot be empty") 5 private Integer; 6 personupdate.jsp 7  8 name: <sf:input path= "name"/> 9 <font color= "Red" ><sf:errors path= "name"/> </font>10 personcontroller.java12 public String saveorupdate (@Valid person p, Bindingresult br,13         @ Requestparam ("photo") Multipartfile file,14         httpservletrequest request, HttpServletResponse repsonse) {     if (Br.haserrors ()) {         return "person/jpersonupdate";  Error returned page display error     

Verify error message Echo

<sf:errors path= "*"/>

Show All Errors

Attention:

Form property modelattribute= "Person"

Otherwise, you will not be able to display error messages

SPRINGMVC Data validation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.