第一步:在dao层接口定义批量删除方

    1. //批量删除
    2. public int delMany(List<Integer> list);

    第二步:在mapper映射文件中写sql语句

    1. <delete id="delMany" >
    2. delete from t_device where d_id in
    3. <foreach collection="list" item="id" open="(" close=")" separator=",">
    4. #{id}
    5. </foreach>
    6. </delete>

    第三步:在service层接口定义批量删除方法

    1. //批量删除
    2. R delMany(List<Device> list);

    第四步:实现service接口方法

    1. public R delMany(List<Device> list) {
    2. ArrayList<Integer> integers = new ArrayList<>();
    3. for (Device device : list) {
    4. integers.add(device.getD_id());
    5. }
    6. if (dao.delMany(integers)>0){
    7. return R.ok();
    8. }
    9. return R.fail();
    10. }

    第五步:在controller层定义方法,与前段进行交互

    1. @RequestMapping("delmany.do")
    2. @ResponseBody
    3. public R delMany(@RequestBody List<Device> list)
    4. {
    5. return service.delMany(list);
    6. }

    第五步:前段ajax

    1. $.ajax({
    2. type:'post',
    3. url:"/api/device/delmany.do",
    4. contentType:"application/json;charset=UTF-8",
    5. data:JSON.stringify(data),
    6. dataType:"json",
    7. success:function (ret) {
    8. }
    9. })