SpringMVC接收对象数组+MyBatis批量处理

 

Controller类代码如下:

@ResponseBody
    @RequestMapping(value="/ecg/addEcgs", method=RequestMethod.POST)
    public Map addEcgs(@RequestBody List ecgBeans){
        Map modelMap = new HashMap();
        ResponseMsg responseMsg = new ResponseMsg();
        System.out.println(ecgBeans.toString());
        if (null == ecgBeans || ecgBeans.size() == 0) {
            responseMsg.set(2, "参数校验失败", null);
            modelMap.put("ResponseMsg", responseMsg);
            return modelMap;
        }
        if(ecgService.addEcgs(ecgBeans)){
            responseMsg.set(1, "批量添加成功", null);
            modelMap.put("ResponseMsg", responseMsg);
        } else {
            responseMsg.set(2, "批量添加失败", null);
            modelMap.put("ResponseMsg", responseMsg);
        }
        
        return modelMap;
    }

 

Ajax代码如下:

 

MyBatis配置文件SQL定义如下:

   
        INSERT INTO lefuyun.tbl_ecg (
            oldPeopleId, 
            agencyId, 
            ecg, 
            inspectTime, 
            inspectStaffId, 
            entryTime, 
            entryStaffId, 
            scene, 
            approvalStatus, 
            createTime, 
            updateTime, 
            reserved
        ) VALUES 
        
            (
                #{item.oldPeopleId,jdbcType=NUMERIC},
                #{item.agencyId,jdbcType=NUMERIC}, 
                #{item.ecg,jdbcType=VARCHAR}, 
                #{item.inspectTime,jdbcType=NUMERIC}, 
                #{item.inspectStaffId,jdbcType=NUMERIC}, 
                #{item.entryTime,jdbcType=NUMERIC}, 
                #{item.entryStaffId,jdbcType=NUMERIC}, 
                #{item.scene,jdbcType=NUMERIC}, 
                #{item.approvalStatus,jdbcType=NUMERIC}, 
                #{item.createTime,jdbcType=NUMERIC}, 
                #{item.updateTime,jdbcType=NUMERIC},
                #{item.reserved,jdbcType=VARCHAR}
            )
        
    

 

转载于:https://www.cnblogs.com/mengyao/archive/2012/07/16/4931523.html

你可能感兴趣的:(java,json,javascript)