Training diary for Form Verification of spring MVC in November 21

Source: Internet
Author: User

You can see a piece of code in htmlfilter:
Stringbuffer result = new stringbuffer (content. Length + 50 );
By the way, I would like to ask some of the ideas and causes of the students, and there are very few respondents. This is a piece of knowledge I have explained before, and many people forget the results. I hope you can remember it again.

Today, I will explain how to use validator in spring MVC to verify form data and analyze the applications of the bindexception, objecterror, and fielderror classes. Description of the messagesourceresolvable. getcodes () method, understanding the function of the string [] codes parameter in the fielderror constructor, and will try the elements one by one to extract information from messageresource.

You can add multiple fielderror and multiple objecterror with the same field to bindexception. You can call the bindexception adderror method, the series of reject methods defined in the errors interface, and several tool methods provided by validationutils. The source file of bindexception is studied and some content related to the dosetnestedpath method is understood. This means that when the reject method is called, an appropriate prefix is added before the input field name.
For the rejectvalue (string field, string errorcode) method, if the field is email, the errorcode is required or invalid, and the generated Message key is an array :.., required. email ,.. and required. Use this array to try one by one in the message resource. For details, see bindexception's string [] resolvemessagecodes (string errorcode) method (note that the parameter here is errorcode) and defaultmessagecodesresolver class (you can quickly retrieve all classes in the help document ).

You must call the setvalidator and setvalidateonbinding methods.

Read the bindexception source file to learn more details, such as how the command object and error object are bound to the request domain: bindexception. the map returned by the GetModel method contains the command object and error object. The onsubmit method uses the following code:
Return new modelandview (getsuccessview (), errors. GetModel ());
The following code is used in the showform method:
Map model = errors. GetModel ();
Return new modelandview (viewname, model );
In the internalresourceview. exposemodelasrequestattributes method, It stores every element of the map object "model" in the request domain.

Through the use of validator, you should better understand the role of the framework: "embed your thoughts into the framework and your wishes, the framework provides an interface for inserting your wishes ".

Write setvalidator (New myvalidator () directly in the program. After the eclipse prompts an error, we can let eclipse automatically generate the myvalidator class for us and automatically implement the validator interface.

At the noon break, I gave a discussion to the new class and explained the design mode of the touch edition method to understand the basic situation and let everyone feel my lecture style.
What is the design model?
Why is there an abstractset between set and hashset/treeset?
How do I write several methods in the abstractset class? What design mode is this?
Will the code of these methods change due to different underlying classes (for example, hashset/treeset?
Method Design Mode: The manager defines the workflow of the consultant's service method. Each work step in the service method is defined in the form of an abstract method. In the future, only one person can be hired as the consultant, it is necessary to inherit the consultant class and implement the abstract methods defined in the consultant. The external interface only interacts with the service method of the consultant, but does not know the existence of other methods called inside the service method. The methods implemented in the subclass are exclusively for the service method call, it is not called by other classes. Each subclass uses different methods to implement these methods. This is like the specific methods used by each consultant to complete each step can be different.

Then, I asked Wang zeyou to explain some of the results of his research on the validator framework and write a simple demo program using the validator framework.
 

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.