The rough flow of using spring validation:
The first step is to have configuration file XML support (Spring_validate.xml). (Of course, in Web. xml)
1<beans xmlns= "Http://www.springframework.org/schema/beans"2Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p"3xmlns:context= "Http://www.springframework.org/schema/context"4Xmlns:mvc= "Http://www.springframework.org/schema/mvc"5xsi:schemalocation="6http//Www.springframework.org/schema/beans7http//www.springframework.org/schema/beans/spring-beans-4.0.xsd8http//Www.springframework.org/schema/context9http//www.springframework.org/schema/context/spring-context-4.0.xsdTenhttp//Www.springframework.org/schema/mvc Onehttp//www.springframework.org/schema/mvc/spring-mvc-4.0.xsd A"> - -<bean id= "Validator" the class= "Org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" > -<property name= "Providerclass" value= "Org.hibernate.validator.HibernateValidator"/> -<!--If you do not add the default to Validationmessages.properties with Classpath -<property name= "Validationmessagesource" ref= "Messagesource"/> +</bean> - + A at<bean id= "Messagesource" - class= "Org.springframework.context.support.ReloadableResourceBundleMessageSource" > -<!--to the path to the server-- -<property name= "basename" value= "Classpath:messages"/> -<property name= "fileencodings" value= "Utf-8"/> -<property name= "cacheseconds" value= "/>" in</bean> - to<bean id= "Webbindinginitializer" + class= "Org.springframework.web.bind.support.ConfigurableWebBindingInitializer" > - the<property name= "Conversionservice" > *<Bean $ class= "Org.springframework.format.support.FormattingConversionServiceFactoryBean" >Panax Notoginseng</bean> - the</property> +<property name= "Validator" ref= "validator"/> A</bean> the +</beans>
And then there's this thing coming up: messages.properties.
and the corresponding place in the model layer should also be reflected.
1 Public classuser{2 3 @NotEmpty4 PrivateString username;5 @NotEmpty6 PrivateString password;7 @NotEmpty8 PrivateString Repassword;9 Ten @NotEmpty One @Email A PrivateString Email; - @NotEmpty - PrivateString XM; the}
The last one is on the JSP page (for personal use of FTL)
The first thing to do is to have these two words: Spring components
1 < #assign spring=jsptaglibs["Http://www.springframework.org/tags"]/>
2 < #assign form=jsptaglibs["Http://www.springframework.org/tags/form"]/>
And then you have to show it in the corresponding input.
1 User name: <input type= "text" name= "username" id= "username" >2< @form. Errors Path= "username"/ >3 Password: <input type= "text" name= "password" id= "password" >4< @form. Errors path= "Password" />
At the end of the note the form form should be written like this. Where CommandName is the lowercase of the entity class name.
1 < @form. form commandname= "user" action= "" method= "Post" name= "" id= "" >
The effect shown is this:
This post is purely personal learning and understanding, if there are errors please the great God.
Spring Checksum (Validator)