[转]java代码中用requestbody的方法接收list集合数据

    xiaoxiao2022-07-04  132

    原文地址:http://www.cnblogs.com/quanyongan/archive/2013/04/16/3024741.html

    干货代码:

    前端代码:

    <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>

    后端代码:

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

     

    最新回复(0)