Springmvc session and model parsing, springmvcmodel

Source: Internet
Author: User

Springmvc session and model parsing, springmvcmodel

There are two ways to use the session in springMVC. The first is to directly pass the httpsession, and the second is to use the @ SessionAttributes ("userId") annotation.

Here with a post, others write especially good, is I have seen the best: http://www.cnblogs.com/waytofall/p/3460533.html

He explained the role of this annotation in detail, so I won't talk much about httpsession. Here I will mainly explain the principle of this annotation.

According to the original interpretation, I also tried the original example. The result is indeed that.

That is to say, this annotation will automatically store the attribute names in the model in the session.

In addition, when the next request arrives at another service class, if the service class also marks this session annotation, it will automatically find this attribute name in the session and fill it in the model object.

You can add a service class based on the example in the address, and try not to mark whether the annotation can be obtained. After marking it, you can get it in the model.

You can only clear the information from the remove Method of the httpsession object.

My opinion and understanding in the following model

The role of the model is the same as the setAttribute (arg0, arg1) of the request. Both Save the value or object, and then take the value in the view. You can also use the ognl expression to take the value.

The question is, why does the springmvc framework use the model object?

My personal understanding is:

Request is only a request. Its function is to initiate a request from the client and carry the parameters contained in the request initiated by the client, obtain parameters in the business layer and process them accordingly. The request object's work should end here, the rest is that the client processes the request and parameters and generates the response to return to the client.

Therefore, the request should not be used to store values to achieve a connection between the model layer and the view layer, therefore, the model or modelandview special object is used for the existence of the model layer and the value of the view layer.

The model will store the value at the model layer. In the view layer, the model will check whether this attribute is used in the model object and render it, the data of the model is automatically cleared after the request is completed.

The above is my personal understanding of the model and request. It's almost 1 o'clock.

 

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.