1.post.html
<!-- 按钮 -->
<div class="cl pd-6 bg-1 bk-gray mt-20">
<span class="l"><a class="btn btn-primary radius" οnclick="publish_post()" href="javascript:void(0);"><i class="Hui-iconfont"></i>发布帖子</a></span>
<span class="l" style="padding-left:10px"><a class="btn btn-primary radius" οnclick="publish_delete()" href="javascript:void(0);"><i class="Hui-iconfont"></i>批量删除</a></span>
</div>
//批量删除的js
function publish_delete(){
var ids="";
$("input:checkbox[name=checkBox]:checked").each(function(index){
//代码调试
// console.log($(this).attr('pid'));
ids+=$(this).attr('pid')+',';
})
layer.confirm('确认要删除吗?',function(index){
post_ajax('/post/deletePostList', {'ids':ids});
layer.msg('已删除!',{icon: 5,time:1000});
window.location.reload();
});
}
2.postController
@RequestMapping(value = "/deletePostList")
@ResponseBody
public Result deletePostList(String ids){
String[] sid=ids.split(",");
List<String> idList=Arrays.asList(sid); //将字符串数组转换为List
Result result=new Result();
try{
boolean isSucceed=postBizService.deleteList(idList);
if(isSucceed){
result =buildSuccessMsg("帖子删除成功");
}else{
result =buildFailMsg("帖子删除失败");
}
}catch(Exception e){
logger.info("business-PostController:"+e.toString());
result =buildFailMsg("帖子删除失败");
}
return result;
}