前臺JSON後臺接收的時候,轉變爲對象的要求@resquestBody的使用

前臺代碼如下

function deleteApplicationController(index){
    alert(index);
    var row = $("#applicationControlList").datagrid('getRows')[index];
    var  applicationControl = new Object();//這個名字是隨便取的,但是它的屬性要與實體BEEN相同
    alert(row.applicationControlId);
    applicationControl.applicationControlId = row.applicationControlId;
    applicationControl.versionNumber = row.versionNumber;
    console.info(applicationControl);
    if(confirm("確定要刪除選中的記錄?")){  
        $.ajax({
            type:'POST',
            contentType : 'application/json;charset=UTF-8',//這句話一定要與後臺@requestBody相應,//如果沒有它的話,只有@requestBody,那麼我們的請求地址會是錯誤的。
            url:'../../applicationControl/deleteApplicationControl',   
            data:JSON.stringify(applicationControl),
            dataType:'json',
            success:function(data){
                if(data.result=='Y'){
                    $("#applicationControlList").datagrid('reload');
                    $.messager.alert('提示','刪除成功');
                }else{
                    $.messager.alert('提示','刪除失敗');
                }
            }
        });
    }
}

後臺代碼

    @RequestMapping("deleteApplicationControl")
    public void deleteApplicationControl(@RequestBody  ApplicationControl applicationControl,HttpServletRequest request,HttpServletResponse response){
        User user = null;
        try{
            user = StringUtil.checkRequest(request);
            //String applicationControlId = request.getParameter("id");
            Long applicationControlId = applicationControl.getApplicationControlId();

            Long applicationId = null;
            if(null != applicationControlId){
                 //applicationId = Long.parseLong(applicationControlId);
            }
            int length = applicationControlService.deleteApplicationControl(applicationControlId);
            Map<String, Object>   resultMap = new HashMap<String, Object>();
            if(length>0){
                resultMap.put(Constant.RESULT, Constant.TRUE);
            }
            StringUtil.outputJsonObject(resultMap,response);
        }catch(Exception e){
            int resultCode = sysLogService.writeLog(SysLogUtil.exceptionLogMap(this, Constant.ERROR_LEVEL, Constant.INFO_DIFFUSION_PUBLISH, Constant.FIND_APPLICATION_CONTROLLER_LIST, e,user.getUserId()));
            StringUtil.exceptionHandle(response,resultCode);
        }
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章