For data of json object type (i.e. JsonObject), springMVC mainly receives the following ways:
1. Receive via Map
@RequestMapping(value = "/getAllStudio" ) public void getAllStudio(@RequestBody Map<String, Integer> map ) { JSONObject json = new JSONObject(); Integer page = map.get("page") ;// Current page Integer rows = map.get("rows") ;// Number of displayed per page}2. Receive by encapsulating data in a vo object
@RequestMapping(value = "/addStudio")public JSONObject addStudio(@RequestBody Studio stu) throws IOException { JSONObject json = new JSONObject(); if(stu==null){ json.put("result",false); return json; } }Supplement: Several common ways to transfer data from posts
When transmitting an http request, the Content-Type field is used to know how the message subject in the request is encoded in the method
1.application/x-www-form-urlencoded
In the form submission method, the transmitted data will be converted into the form of data1=1&data2=2.
In the controller layer, it can be obtained by request.getParametre("data1");.
This form is generally used when Ajax submits data.
2.multipart/form-data
The format specified when uploading multiple files.
3.application/json
Transfer data in json format.
This brief summary of springMVC receiving front-end json data is all the content I share with you. I hope it can give you a reference and I hope you can support Wulin.com more.