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コードは次のとおりです.
<span style="color:#000000;">
        $(document).ready(function(){
            var arr </span>= <span style="color:#0000ff;">new</span><span style="color:#000000;"> Array();
            var data </span>=<span style="color:#000000;"> {
                oldPeopleId:</span>1<span style="color:#000000;">,
                agencyId:</span>1<span style="color:#000000;">,
                ecg:</span>1<span style="color:#000000;">,
                inspectTime:</span>111<span style="color:#000000;">,
                inspectStaffId:</span>1<span style="color:#000000;">,
                entryTime:</span>111<span style="color:#000000;">,
                entryStaffId:</span>1<span style="color:#000000;">,
                scene:</span>1<span style="color:#000000;">,
                approvalStatus:</span>1<span style="color:#000000;">,
                createTime:</span>111<span style="color:#000000;">,
                updateTime:</span>111<span style="color:#000000;">,
                reserved:</span>1<span style="color:#000000;">
                    
            };
            arr.push(data);
            arr.push(data);
            alert(JSON.stringify(arr));
            $.ajax({  
                type: </span>'POST'<span style="color:#000000;">,  
                url: </span>'singndata/ecg/addEcgs'<span style="color:#000000;">,  
                contentType: </span>'application/json;charset=utf-8'<span style="color:#000000;">,
                dataType: </span>'json'<span style="color:#000000;">,  
                data: JSON.stringify(arr),  
                success: function(data){
                    console.debug(data);
                },  
                error: function(err){  
                    console.debug(data); 
                }  
            });  
            
        });

    </span>

 
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