首页 > 代码库 > SpringMVC @RequestBody接收Json对象字符串

SpringMVC @RequestBody接收Json对象字符串

JavaScript 代码:

<script type="text/javascript">      $(document).ready(function(){          var saveDataAry=[];          var data1={"userName":"test","address":"gz"};          var data2={"userName":"ququ","address":"gr"};          saveDataAry.push(data1);          saveDataAry.push(data2);                 $.ajax({             type:"POST",             url:"user/saveUser",             dataType:"json",                  contentType:"application/json",                           data:JSON.stringify(saveData),             success:function(data){                                                    }          });     });  </script> 

Java代码

    @RequestMapping(value = "http://www.mamicode.com/saveUser", method = {RequestMethod.POST }})     @ResponseBody      public void saveUser(@RequestBody List<User> users) {          userService.batchSave(users);     } 

SpringMVC @RequestBody接收Json对象字符串