The Content-type=application/json of process analysis of interface parameter resolution in SPRINGMVC

Source: Internet
Author: User

The previous blog analyzed the parameter resolution in Content-type by default. Today, let's look at what happens when you specify Content-type as Application/json. Compared with the previous default, there is a difference in the place below. Request.getparameternames () in the default content-type=application/x-www-form-urlencoded; The value can be obtained when charset=utf-8, but not in the case of Content-type=application/json. By querying the data, Tomcat treated the content-type=application/x-www-form-urlencoded with special treatment, Content-type not application/ The x-www-form-urlencoded POST request does not read the request body data and does the corresponding parameter processing, that is, the form data is not parsed to be placed in the request parameter map. So through Request.getparameter (name) is not available. Therefore, there is no argument to parse when there is no backend @responsebody this annotation.

Next we look at the addition of @responsebody after the analysis of the parameters. In the following position, the situation has changed, if the Springmvc method parameter is preceded by a @responsebody, the resolver implementation class will not add this annotation. This resolver is an example of servletmodelattributemethodprocessor when no annotations are added, and resolver is an instance of Requestresponsebodymethod after adding annotations.

Therefore, in the Requestresponsebodymethod class in the Resolveargument method to parse the parameters,

As you can see from this readwithmessageconverters method, this is read through the IO stream

The Content-type=application/json of process analysis of interface parameter resolution in SPRINGMVC

Related Article

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.