Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Spring MVC @ RestController receives POST requests and receives them with Map

Shulou Source: shulou.com Published: 2022-06-03 07:03:09 11月06日 Update

Background

After breaking away from traditional projects and using micro-service cluster development. The RestFul style is imperative, so this article is aimed at writers who use the restful style.

Theme

What are the parameters submitted by the restful post request to be received?

Keyword

Map 、 Entity

Content

1. First of all, the traditional receiver uses HttpServletRequest to support both get hello submission and form form post submission, and the background gets the value using req.getParement ("name").

2. So, for WeChat Mini Programs's lack of form submission function, what should we do? You can only choose to submit in the form of ajax, which is now commonly used in web, app and Mini Program. Just submit a JSON string.

3. The modification of the server is to delete the HttpServletRequest parameter and use the

@ RequestBody Map body

Form, (Spring MVC will automatically encapsulate the passed JSON string into the map type. According to the instructions on the official website, we need to create our own Entity receiving parameters. But my project database uses MongoDB, all the operations are Map to save to create Entity, in addition, too lazy

)

Last

-using the above style, please fully enable the Restful style and replace @ Controller with @ RestController

-@ RequestMapping uses method to specify

2017-10-16 16:07 at Huixin IBC, Xi'an

Foam gold

Tags: Style parameters form tradition characters strings that is programs forms projects services imperative themes people keywords keywords content functions and at the same time background Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft Redmi Shulou Technology Shulou Tech Info