一、给全部删除一个id
删除
二、发送ajax请求
//点击全部删除,就批量删除
$("#emp_delete_all_btn").click(function(){
var empNames = "";
var del_idstr = "";
$.each($(".check_item:checked"),function(){
//this
empNames += $(this).parents("tr").find("td:eq(2)").text()+",";
//组装员工id字符串
del_idstr += $(this).parents("tr").find("td:eq(1)").text()+"-";
});
//去除empNames多余的,
empNames = empNames.substring(0, empNames.length-1);
//去除删除的id多余的-
del_idstr = del_idstr.substring(0, del_idstr.length-1);
if(confirm("确认删除【"+empNames+"】吗?")){
//发送ajax请求删除
$.ajax({
url:"${APP_PATH}/emp/"+del_idstr,
type:"DELETE",
success:function(result){
alert(result.msg);
//回到当前页面
to_page(currentPage);
}
});
}
})
三、改造EmployeeController
/**
* 单个批量二合一
* 批量删除:1-2-3
* 单个删除:1
* @param id
* @return
*/
@ResponseBody
@RequestMapping(value="/emp/{ids}",method=RequestMethod.DELETE)
public Msg deleteEmp(@PathVariable("ids")String ids) {
//批量删除
if(ids.contains("-")){
List del_ids = new ArrayList();
String[] str_ids = ids.split("-");
//组装id的集合
for (String string : str_ids) {
del_ids.add(Integer.parseInt(string));
}
employeeService.deleteBatch(del_ids);
}else {
Integer id = Integer.parseInt(ids);
employeeService.deleteEmp(id);
}
return Msg.success();
}
四、EmployeeService新增
public void deleteBatch(List ids) {
// TODO Auto-generated method stub
EmployeeExample example = new EmployeeExample();
Criteria criteria = example.createCriteria();
criteria.andEmpIdIn(ids);
employeeMapper.deleteByExample(example);
}