Previously, always thought in the SPRINGMVC environment, @RequestBody received a JSON object, has been debugging the code is not successful, and later found that, in fact, @RequestBody receive a JSON object string, rather than a JSON object. In AJAX requests, however, the JSON object is often passed, and it is later discovered that the object can be converted to a string using the Json.stringify (data) method. At the same time Ajax request also specify datatype: "JSON", ContentType: "Application/json" so you can easily upload an object or list to the Java side, You can bind an object or list using @requestbody.
JavaScript Code:
1<script type= "Text/javascript" >2 $ (document). Ready (function () {3var savedataary=[]; 4var data1={"UserName": "Test", "Address": "GZ"}; 5var data2={"UserName": "Ququ", "Address": "GR"}; 6 Savedataary.push (DATA1); 7 Savedataary.push (DATA2); 8 $.ajax ({9Type: "POST", TenURL: "User/saveuser", OneDataType: "JSON", AContentType: "Application/json", - data:JSON.stringify (saveData), - success:function (data) { the - } - }); - }); +</script>
Java code
1 @RequestMapping (value = "Saveuser", method =2 @ResponseBody 3 Publicvoid saveuser (@RequestBody list<user>4 5
SPRINGMVC @RequestBody receive JSON object strings