ajax传递List参数

js部分:
var groupDetails = new Array();
$("#pjcSelect2 option").each(function () {
   var groupDetail = {
       groupId : model.id,
       groupName : model.groupName,
       projectName : $(this).attr("data-name"),
       projectId : $(this).val()
   }
   groupDetails.push(groupDetail);
})
$.ajax({
    url : '/basicgroup/updatebasicgroup',
    data : JSON.stringify(groupDetails),//将对象序列化成JSON字符串 ,
    dataType : 'json',
    method : 'post',
    // traditional : true, //阻止深度处理数据
    contentType : 'application/json;charset=utf-8', //设置请求头信息
    success : function (data) {
        console.log(data);
    }
})

java Controller:

@RequestMapping(value = "updatebasicgroup")
    public ApiResultDto updateBasicGroup(HttpServletRequest request, @RequestBody List list){
        ApiResultDto resultDto = new ApiResultDto();
        resultDto.setSuccess(true);
        try{
            HttpSession session = request.getSession();
            PlatformOperatorDto operatorDto = (PlatformOperatorDto) session.getAttribute("operation");
            /*basicGroupDto.setCreateUser(operatorDto.getOperatorName());*/
//            basicGroupDto.setModifyTime(new Date());
//            int i = medicalIntegration.updateBasicGroup(basicGroupDto,list);
//            if(i > 0){
//                resultDto.setSuccess(true);
//            }
        }catch (Exception e){
            e.printStackTrace();
            //日志
        }
        return resultDto;
    } 
  

                            
                        
                    
                    
                    

你可能感兴趣的:(ajax传递List参数)