/*多条-删除*/
function deleteBatch(){
layer.confirm('确认要删除吗?',function(index){
var idList = new Array();
// 获得选中的ID值
$("input[name='id']:checkbox:checked").each(function(){
idList.push(this.value);
});
$.ajax({
type:"post",
url:"${CONTEXT_PATH}/sys/menu/deletebatch.html",
data: $('#form-menu').serialize(),//表单数据
data: {"idList":idList},
//cache:false,
success:function(msg){
if(msg=="success"){
// 延时1S刷新
setTimeout('location.replace(location.href)', 1000);
layer.msg('全部删除成功!',{icon:1,time:1000});
}
if(msg=="error"){
layer.msg('异常!');
}
}
});
});
}
后台controller:
@RequiresPermissions("sys:menu:edit")
@ResponseBody
@RequestMapping("/deletebatch")
public String deletebatch(@RequestParam("idList[]") List<String> objs,ModelMap modelMap, HttpServletRequest request) throws Exception {
String retStr = "error";
try{
menuService.removeMulti(objs);
retStr = "success" ;
}catch(Exception e) {
logger.info(e.getMessage());
}
return retStr;
}
后台service:
@CacheEvict(value="defaultCache",allEntries=true)
public void removeMulti(List<String> objs) {
BasicDBList basicDBList=new BasicDBList();
for(String id : objs) {
basicDBList.add(new BasicDBObject("id",id));
}
DBObject obj =new BasicDBObject();
obj.put("$or", basicDBList);
Query query=new BasicQuery(obj);
mongoTemplate.remove(query,Menu.class);
}
如果不跳转,应该把ajax里面的dataType改成html ,json时返回不正确
posted on 2016-10-27 13:22
liufx 阅读(681)
评论(0) 编辑 收藏