JS代码
function ondelRow(){
var ids=$("#table_list").jqGrid("getGridParam","selarrrow");//获取选中的行(数组)
if(ids.length>0){
var id = ids.toString();
$.post("${ctx}/pems/property/deleteAll",{"ids":id},function(data) {
var s=2;
if(data.indexOf("除成")>0){
s=1;
}
layer.msg(data, {icon:s});
refresh();
});
}else{
layer.alert('请先选择数据', {
skin: 'demo-class',
icon: 2,
time: 3500,
title:'提示',
offset: '150px',
closeBtn: 0
})
}
}
JSP代码
<button class="my_button btn" οnclick="ondelRow()" data-toggle="tooltip" data-placement="top"><i class="fa fa-trash-o"> 删除</i> </button>
后台代码
@ResponseBody //注解,自动将string转换成json返回给ajax
@RequiresPermissions("pems:property:del")
@RequestMapping(value = "deleteAll")
public String deleteAll(String ids, Model model) {
String idArray[] =ids.split(",");
int code=0;
int sum=0;
for(String id : idArray){
Building judge = buildingService.selectById1(propertyService.get(id).getId());
//判断如果物业下没有楼座就可以删除
if(judge==null){
try{
code = propertyService.delete10(propertyService.get(id));
if (code!=1) {
return "删除失败,请联系管理员";
}else {
sum+=1;
}
}catch(Exception e){
return "系统错误,请联系管理员";
}
// propertyService.delete(propertyService.get(id));
}else{
return "成功删除"+sum+"条数据!"+ "物业"+propertyService.get(id).getName()+"下有楼座,不能删除";
// return "redirect:"+adminPath+"/pems/property/list?repage";
}
}
return "删除成功"+sum+"条数据!";