删除多条商品

<script type="text/javascript">
        $(function(){
            /** 获取上一次选中的部门数据 */
            var boxs  = $("input[type='checkbox'][id^='box_']");
            
           /** 给全选按钮绑定点击事件  */
            $("#checkAll").click(function(){
                // this是checkAll  this.checked是true
                // 所有数据行的选中状态与全选的状态一致
                boxs.attr("checked",this.checked);
            })
            
           /** 给数据行绑定鼠标覆盖以及鼠标移开事件  */
            $("tr[id^='data_']").hover(function(){
                $(this).css("backgroundColor","#eeccff");
            },function(){
                $(this).css("backgroundColor","#ffffff");
            })
            
            
            /** 删除员工绑定点击事件 */
            $("#delete").click(function(){
                /** 获取到用户选中的复选框  */
                var checkedBoxs = boxs.filter(":checked");
                if(checkedBoxs.length < 1){
                    $.ligerDialog.error("请选择一个需要删除的部门!");
                }else{
                    /** 得到用户选中的所有的需要删除的ids */
                    var ids = checkedBoxs.map(function(){
                        return this.value;
                    })
                    
                    $.ligerDialog.confirm("确认要删除吗?","删除部门",function(r){
                        if(r){
                            // alert("删除:"+ids.get());
                            // 发送请求
                            //window.location = "${pageContext.request.contextPath}/dept/removeDept?ids=" + ids.get();
                           $.get("${pageContext.request.contextPath}/dept/removeDept.do?ids="+ids.get(),
                               function (data) {
                                       if (data == "OK"){
                                           alert("部门删除成功!");
                                           window.location.href = "${pageContext.request.contextPath}/dept/findDept.do";
                                    } else if (data == "FAIL") {
                                        alert("部门删除失败!");
                                        window.location.reload();
                                    } else if(data == "ERROR"){
                                        alert("该部门存在员工,不能删除!");
                                        window.location.reload();
                                    }else {
                                        alert("内部服务器异常!");
                                        window.location.reload();
                                    }
                           });


                        }
                    });
                }
            })
        })
    </script>
 <tr valign="top">
        <td height="20">
          <table width="100%" border="1" cellpadding="5" cellspacing="0" style="border:#c2c6cc 1px solid; border-collapse:collapse;">
            <tr class="main_trbg_tit" align="center">
              <td><input type="checkbox" name="checkAll" id="checkAll"></td>
              <td>部门名称</td>
              <td>详细信息</td>
              <td align="center">操作</td>
            </tr>
            <c:forEach items="${requestScope.depts}" var="dept" varStatus="stat">
                <tr id="data_${stat.index}" align="center" class="main_trbg" onMouseOver="move(this);" onMouseOut="out(this);">
                    <td><input type="checkbox" id="box_${stat.index}" value="${dept.id}"></td>
                     <td>${dept.name }</td>
                      <td>${dept.remark }</td>
                     <td align="center" width="40px;">
                     <a href="${pageContext.request.contextPath}/dept/findDeptById.do?id=${dept.id}">
                            <img title="修改" src="${pageContext.request.contextPath}/images/update.gif"/>
                    </a>
                      </td>
                </tr>
            </c:forEach>
          </table>
        </td>
      </tr>
 @RequestMapping("/removeDept.do")
    @ResponseBody
    public String removeDept(Integer[] ids){
        //System.out.println(ids[0]);
        try {
            int rows = deptService.removeDept(ids);
            if (rows == ids.length){
                return "OK";
            }else {
                return "FAIL";
            }
        }catch (DataIntegrityViolationException e){
            return "ERROR";
        }
    }
  <delete id="deleteEmployee">
        delete from employee_inf where id in
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </delete>

猜你喜欢

转载自www.cnblogs.com/liuna369-4369/p/11040024.html
今日推荐