ajaxはjson配列をコミットする.

1453 ワード

SpringMVC @RequestBody  Json     ​  ,     SpringMVC   ,@RequestBody      Json  ,            ,    ,   @RequestBody      Json      ,     Json  。   ajax        Json  ,      JSON.stringify(data)             。  ajax         dataType: "json",contentType:"application/json"                List  Java 
js  
  
    $(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){ 
                                       
            } 
         }); 
    });  
 
  
java  
@RequestMapping(value = "saveUser", method = {RequestMethod.POST }}) 
    @ResponseBody  
    public void saveUser(@RequestBody List users) { 
         userService.batchSave(users); 
    }