前台代码如下
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);
}
}