因为自己在网上找了半天,都找不到完整地代码(脑袋笨,不会变通到自己项目里),所以在这里记下了近乎完整的代码
前端代码
<span style="cursor:pointer;" class="delete"><a class="del-myBlog" onclick="delMyBlog()">删除选中</a></span> //前端代码
+‘<td width="20"><input type="checkbox" name="quanxuani" id="check" value=‘+comment.id+‘></td>‘ //javascript拼接的数据,checkbox的value为id
javascript代码
<script type="text/javascript">
//删除选中博文 (我的博文)
function delMyBlog(){
var ques_id = [];
$("[name=quanxuani]:checked").each(function(){
ques_id.push($(this).val());
});
if(ques_id!=‘‘ && ques_id!=null){
alert("确定要删除吗?");
$.post(‘../../Blog/deleteImByIds.do‘,{‘qid‘:ques_id},function(data){
if (data == "0")
alert("删除失败!");
else {
alert("删除成功!");
window.location=‘fav_blog.html‘;
getusers();
}
});
}else{
layer.msg(‘请先选择要删除的内容‘);
}
}
</script>
后台接收
@RequestMapping(value="/deleteImByIds.do")
public void deleteImByIds(@RequestParam(value = "qid[]") String[] titles) throws ParseException{
int aa = 0;
int sum = 0;
System.out.println("ss");
for (String ss : titles) {
aa=bgdao.deleteImByIds(Integer.parseInt(ss));
sum = sum + aa;
}
}
mybatis语句 dao、service..方法参数 public int deleteImByIds(int id);
<!-- 删除选中博文 deleteImByIds -->
<delete id="deleteImByIds" parameterType="java.lang.Integer">
delete from ZDCJ_BLOG where id in #{id}
</delete>