What I learned today
- SPRINGMVC form validation based on Hibernate validator:
http://blog.csdn.net/wuyt2008/article/details/8597312
Summary of steps:
- Add dependencies to the Pom file
- Add the appropriate annotations on the bean that needs to be validated
The following annotations are available:
@NotEmpty
@NotBlank (message= "property cannot be empty")
@Size (min= 3, max= , message= "property length only between 3-20")
@Pattern (regexp = "^[a-za-z_][a-za-z_0-9]*$", message= "user name is malformed") //Regular expression
@Email (message= "mailbox format is incorrect")
- Add @valid annotations to the bean on which the controller accepts parameters
- Add a property modelattribute="BEAN" to the previous paragraph submission form form
- Four meta-note links in Java: http://www.cnblogs.com/Gordon-YangYiBao/archive/2012/08/07/2626340.html
[Email protected]: The purpose of the annotations
Format:
@Target (Type,field,method,parameter,constructor,local_variable,annotation_type,package)
Range:
Type: Interface, class, enumeration, annotation
Field: Constants for fields, enumerations
Method: Methods
PARAMETER: Method Parameters
CONSTRUCTOR: Constructors
local_variable: Local Variables
Annotation_type: Annotations
Package: Packages
[Email protected]: Where to leave annotations
Format @retention (Retentionpolicy.source)
Range:
Source: Annotations exist only in the source code and are not included in the class bytecode file
Class: Default retention policy, annotations exist in the class bytecode file, but are not available at runtime
Runtime: Annotations exist in the class bytecode file and can be retrieved at run time through reflection
2016/11/4