ssm批量删除总结

先从Mapper.xml里面开始写:

然后在mapper.java中写接口

业务逻辑层的接口太简单就不写了,直接写实现层 :

@Override
    public int deletePartlyByID(Integer[] arr) {
        if(arr!=null&&arr.length>0) {
            return productMapper.deletePartlyByID(arr);
        }
        else {
      return 0;
        }
    }

后端控制器的代码如下:

//批量删除
    @RequestMapping("/deleteBatchProducts")
    public void deleteBatchProducts(Integer[] ids,HttpServletResponse response) throws IOException {
        int n=productService.deletePartlyByID(ids);
        if(n>0){
            response.setCharacterEncoding("utf-8");
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().print("<script>alert('批量删除成功');"
                    + "location.href='getProductPage';</script>");
        }
    }

jsp页面代码如下:

 <tbody>
                <c:forEach var="product" items="${productList}">
                    <tr>
                        <td><input type="checkbox" name="ids" value="${product.id}" />${product.id}</td>  

猜你喜欢

转载自blog.csdn.net/qq_40434646/article/details/81119951