Controller取得ajax传递的json

前端之家收集整理的这篇文章主要介绍了Controller取得ajax传递的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 = "saveUser",method = {RequestMethod.POST }}) 
    @ResponseBody  
    public void saveUser(@RequestBody List<User> users) { 
         userService.batchSave(users); 
    } 

猜你在找的Ajax相关文章