/*多條-刪除*/
function deleteBatch(){
layer.confirm('確認(rèn)要?jiǎng)h除嗎?',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(),//表單數(shù)據(jù)
data: {"idList":idList},
//cache:false,
success:function(msg){
if(msg=="success"){
// 延時(shí)1S刷新
setTimeout('location.replace(location.href)', 1000);
layer.msg('全部刪除成功!',{icon:1,time:1000});
}
if(msg=="error"){
layer.msg('異常!');
}
}
});
});
}
后臺(tái)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;
}
后臺(tái)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);
}
如果不跳轉(zhuǎn),應(yīng)該把a(bǔ)jax里面的dataType改成html ,json時(shí)返回不正確
posted on 2016-10-27 13:22
liufx 閱讀(691)
評(píng)論(0) 編輯 收藏