Spring MVC @ RestController receives POST requests and receives them with Map
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