赞
踩
批量删除的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
全选操作
//全选或清空
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;
}
}
}
批量删除按钮
表单增加onSubmit事件
function checkForm(){
var boxs =document.getElementsByName("chk_uid");
for( i=0 ; i<boxs.length ; i++) {
if(boxs[i].checked==true){
if(confirm("确定批量删除这些数据吗?")){
return true;
}else{
return false;
}
}
}
alert("至少选中一条数据……");
return false;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。