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