jsp中對資料進行批量刪除操作
阿新 • • 發佈:2018-11-09
批量刪除的SQL:delete from user where uid in(主鍵列表);
UserBiz:
//批量刪除
public boolean batchDelete(String[] uids);
UserBizImpl:
public boolean batchDelete(String[] uids) { String sql = "delete from user where uid in("; for(String uid:uids){ sql+=uid+","; } //去掉最後一個逗號,增加一個) sql = sql.substring(0, sql.length()-1); sql+=")"; Object[] params={};//沒有引數 return udao.update(sql, params); }
UserServlet:
HttpServletResponse response) throws ServletException, IOException{ //獲取批量編號(注意,複選框的name值為chk_uid) String[] uids = request.getParameterValues("chk_uid"); boolean result = ubiz.batchDelete(uids); if(result == true){ //批量成功 request.setAttribute("msg", "操作成功"); }else{ request.setAttribute("msg", "操作失敗"); } findAllUser(request,response); }
userlist.jsp
全選操作
批量刪除按鈕
表單增加onSubmit事件
//全選或清空 function setChecked(boxname) { var boxs =document.getElementsByName(boxname); var chkbox = document.getElementById("chkall"); if(chkbox.checked == true){ for( i=0 ; i<boxs.length ; i++) { boxs[i].checked = true; } }else{ for( i=0 ; i<boxs.length ; i++) { boxs[i].checked = false; } } }
轉自:https://blog.csdn.net/new_codeer/article/details/51713645