2016/11/4

Source: Internet
Author: User

What I learned today

    • SPRINGMVC form validation based on Hibernate validator:

http://blog.csdn.net/wuyt2008/article/details/8597312

Summary of steps:

    1. Add dependencies to the Pom file
    2. 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")  

    1. Add @valid annotations to the bean on which the controller accepts parameters
    2. 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

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.