mybatis springmvc批量删除


    /**
     * 批量删除 batch
     */
    @RequestMapping(value="/batchDeletes",method=RequestMethod.POST)
    @ResponseBody
    public ModelAndView batchDeletes(HttpServletRequest request,HttpServletResponse response){
        String items = request.getParameter("creditIdbox");
        List<String> delList = new ArrayList<String>();
        String[] strs = items.split(",");
        for (String str : strs) {
            delList.add(str);
        }
        creditService.batchDeletes(delList);
        List<Credit> list=creditService.queryUserInfo(null);
          ModelAndView mv = new ModelAndView();
          Map<String, Object> model = new HashMap<String, Object>();
          model.put("creditVOList", list);
          mv.addAllObjects(model);
          mv.setViewName("queryregister");
          return mv;
    }

 

<!--批量删除 -->
    <delete id="batchDeletes" parameterType="java.util.List">
            DELETE FROM t_credit where t_credit_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">   
            #{item}   
         </foreach>
    </delete>

方法二:

@RequestMapping("/deleteuser")
    public ModelAndView deleteUser(CreditVO creditVO,HttpServletRequest request) {
          String creditId=request.getParameter("creditIdbox");
          if (creditId != null){
              String[] str=creditId.split(",");
             for (int i = 0; i < str.length; i++) {
                 creditService.deleteUser(Integer.valueOf(str[i]));
            }
          }      
                                
          List<Credit> list=creditService.queryUserInfo(null);
        ModelAndView mv = new ModelAndView();
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("creditVOList", list);
        mv.addAllObjects(model);
        mv.setViewName("queryregister");
        return mv;
    }

         <a id="delete" href="http://localhost:8080/ssmy2/CreditController/deleteuser.do?creditIdbox=${credit.creditId}">删除</a>



  <delete id="deleteUser" parameterType="java.lang.Integer">
        DELETE FROM t_credit WHERE
        t_credit_id=#{creditId}
    </delete>


jsp

   function selectAll(){
     if ($("#SelectAll").is(":checked")) {
         $(":checkbox").prop("checked", true);//所有选择框都选中
     } else {
         $(":checkbox").prop("checked", false);
     }
 }
   $(function(){
        $("#deleteuser").click(function(){
             //判断至少写了一项
               var checkedNum = $("input[name='creditIdbox']:checked").length;
            console.log(checkedNum);
               if(checkedNum==0){
                   alert("请至少选择一项!");
                   return false;
            }
               if(confirm("确定删除所选项目?")){
                    var checkedList = new Array();
                    $("input[name='creditIdbox']:checked").each(function(){
                        checkedList.push($(this).val());
                    });
                    console.log(checkedList[0]);
                    $.ajax({
                        type:"POST",
                        url:"http://localhost:8080/ssmy/CreditController/batchDeletes.do",
                        data:{"creditIdbox":checkedList.toString()},
                        datatype:"html",
                        success:function(data){
                            $("[name='creditIdbox']:checkbox").attr("checked",false);
                            alert.dialog.tips('删除成功!');
                            setTimeout("location.reload()",1000);//页面刷新
                        },
                        error:function(data){
                            alert.dialog.tips('删除失败!');
                        }
                    });
                    }
            /* var form=$("#registerform");
            form.prop("action","http://localhost:8080/ssmy/CreditController/deleteuser.do");
            form.submit();  */
     });


<div id="head">
     <form id="registerform" name ="registerform" action="" method="post" enctype="multipart/form-data">
     <div class="search-box" style="width:100%;height:40px;">
                <label> 登录名: </label>
                <input type="text" name="loginName" id="loginName" />
                <label style="margin-left:10px;">身份证:</label>
                <input type="text" name="IDCard" id="IDCard" />
                        <label style="margin-left:10px;"> 提交状态:</label>  
                        <select id="status" name="status" style="width:100px;height:20px;">
                    <option value="">全部</option>
                    <option value="0">已提交</option>
                    <option value="1">未提交</option>
                 </select>
                  <input type="button"  id="button" value="查询" style="width:65px;height:22px;margin-left:20px;"/>
                  <input type="submit"  id="exports" value="导出" style="width:65px;height:22px;margin-left:20px;"/>
                 
        </div>
        <input type="hidden" name="status" id="statushidden" value="${status }" />
        <input type="hidden" name="totalcount" id="totalcount" value="${totalcount }" />
        <table border="0" cellpadding="0" cellspacing="0">
           <tr style="width:100%; height: 50px;">
             <td>
             <input type="checkbox" id="SelectAll" name="SelectAll" οnclick="selectAll();" style="margin-right:5px;"/>全选</td>
             <td>序列</td>
             <td >登录名</td>
             <td >登录密码</td>
             <td >确认密码</td>
             <td >身份证号</td>
             <td >固定电话</td>
             <td >手机号码</td>
             <td >邮箱</td>
             <td >居住地址</td>
             <td id="address">提交状态</td>
             <td >创建时间</td>
             <td >操作</td>
           </tr>
           <c:forEach var="credit" items="${creditVOList}" varStatus="status">
           <tr style="width: 300px;">
           <td><input type="checkbox" name="creditIdbox" id="creditIdbox" value="${credit.creditId }"></td>
           <td>${status.index}</td>
           <td>${credit.loginName}</td>
           <td>${credit.loginPwd}</td>
           <td>${credit.againPwd}</td>
           <td>${credit.IDCard}</td>
           <td>${credit.fixedTelephoneNumber}</td>
           <td>${credit.telephoneNumber}</td>
           <td>${credit.email}</td>
           <td id="address">${credit.address}</td>
           <td>${credit.status ==0 ? '已提交':'未提交'}</td>
           <td>${creditVO.createtime}</td>
           <td>
       <!--  <a id="delete" href="http://localhost:8080/ssmy/CreditController/deleteuser.do?creditIdbox=${credit.creditId}">删除</a>-->
         <a id="delete" href="http://localhost:8080/ssmy/CreditController/deleteuserbatchDeletes.do?creditIdbox=${credit.creditId}">删除</a>
               </td>
           </tr>
           </c:forEach>
       </table>
          <c:if test="${empty creditVOList }">
              没有任何员工信息.
         </c:if> <br/>
          <input type="button" value="删除" id ="deleteuser" >
          <input type="text" name="username"/>
          <input type="file" name="uploadFile"/>
          <input type="submit" id="uploadFile" name="开始上传文件" value="开始上传文件"/>
         <div id="box" style="border: 1px solid #ccc;"></div>
         
     </form>
     
     <a href="http://localhost:8080/ssmy/CreditController/downloadFile.do?fileName=inputik201612061447.JPG">下载文件 </a><br />
       
</div>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值