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