SpringMVC uses springmvcpayload as the backend Receiving Method for sending HTTP request form data and request payload.

Source: Internet
Author: User

SpringMVC uses springmvcpayload as the backend Receiving Method for sending HTTP request form data and request payload.

Recently, when I was working on a project, I found that when I submitted data through the front-end, When I submitted the form through form and sent the json via ajax, springMVC background recipients could not all be processed through @ ModelAttribute. After some searches, when ajax sends a json request, the backend receives data through @ ResponseBody. However, I am not satisfied with this. I have made more research and summarized it as follows:

1. The form and ajax send a json request to submit the query request header and display the distribution as shown in,

After comparisonConclusion 1;

If the Content-Type of the request is set to application/x-www-form-urlencoded, the Post request is considered an http post form request and the parameter appears in form data; other scenarios such as POST requests using native AJAX if the Request Header is not specified, the default Content-Type is text/plain; charset = UTF-8, or application/json, parameters appear in the Request payload block.

If the project only works here, it is too simple. As mentioned above, parameters are received in the form data background through @ ModelAttribute or @ RequestParam; the Request payload block is received by @ RequestBody in the background. However, the problem arises again. How can we format or convert the data sent from the foreground before receiving the data in these two ways, how to map json data objects or convert objects into json data and send them back to the foreground. These questions will be discussed in the next blog

 

Please use the mobile phone "scan" x

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.