Spring-Validator Description Documentation

xiaoxiao2021-03-06  102

Spring-Validator is the main intention to provide simplicity, configurable, realization of Spring MVC, and improve Spring's development efficiency.

-

The main function is:

Use formulated files,

1. Provide Spring client authentication mechanism;

2. Provide configurable verification of Spring server-side universal;

If you are interested, please go

Http://sourceforge.net/projects/js-validation/ Download, there is an example, I suggest you look at the example (or see the example of Struts-Validator can also, the effect is similar).

Next, I will specify

1. Use of the client

2. Server-end

Because the configuration file is the same in Struts, and Struts is so popular, extensive, so do not say the formulation of the file, check the Struts related information (simply modify the validator-rules.xml under the distant, validation.xml can)

1. Use of the client

The principle is to generate the corresponding JavaScript in the JSP page, then click Submit, and the way many people hate this method, but this is the fastest and most direct application. , P: personal feeling, no data basis).

For the specific process, of course, first develop pages and procedures, then think of joining the verification mechanism, if the name cannot be empty, the birthday must be YYYY-MM-DD, etc. One jump, then, let's get started, 嘿嘿

First, the configuration is first, declare the FORM that needs to be verified in Validation.xml.

Second, in -Servlet.xml, declare ApachValidatorResolvers

Validator-rules.xml, validation.xml

Bean's ID is not necessarily called ApachValidatorResolvers, and it is used to it. It is an initialization configuration, which requires the location of Validator-Rules.xml, Validation.xml, due to lazy, and also provides the default value to show its use.

Then, declaration JavaScriptValidator

Similarly, ID does not make requirements. It is mainly to generate the desired JavaScript to provide Taglib or Interceptor or other.

Finally, it is the revision of JSP. Add to verify the declaration of TAGLIB

<% @ taglib prefix = "VLD" URI = "

http://www.avidmouse.com/tags "%>

In the appropriate location (behind the Form), add TAGLIB reference

Page default is 0, so Page = "0" can be omitted

Ok, enjoy it.

2. The principle of the server side, implement org.springframework.validation.valiDator, providing a universal validator.

The specific process, and the client is similar, when you need to add a verification

First, the FORM that needs to be verified in validation.xml.

Second, in -Servlet.xml, declare ApachValidatorResolvers

Validator-rules.xml, validation.xml

Then, a verification bean is declared for the FORM that needs to be verified.

com.avidmouse.validator.simple.bus.registrationform

registrationform

0

Formclass is the CommandClass of SimpleFormController

ValidatorName is a FORM name declared in the formulation

Page default is 0, if it is 0, you can not declare.

Finally, declare the bean of Bean that needs to be verified as the Bean in the previous step.

true com.avidmouse.validator.simple.bus.registrationform

registration

reginfo

Ok, enjoy it again.

转载请注明原文地址:https://www.9cbs.com/read-123557.html

New Post(0)