java根据id批量删除

1.mapper.xml

传入的参数可以是List也可以是Array数组,ParameterType都写List就可以 collection="array"也可以写成collection=“lsit”

 

1
2
3
4
5
6
7
  <!--批量删除-->
<delete id="deleteMenuIds" parameterType="java.util.List">
    delete from sys_menu where menu_id in
    <foreach collection="array" open="(" close=")" separator="," item="id">
        #{id}
    </foreach>
</delete>

 

2.dao层

1
int deleteMenuIds(Long[] ids);

  

3.pojo层

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.qingfeng.pojo;
 
import java.io.Serializable;
 
public class SysMenu implements Serializable {
    private Long menuId;
 
    private Long parentId;
 
    private String name;
 
    private String url;
 
 
    public Long getMenuId() {
        return menuId;
    }
 
    public void setMenuId(Long menuId) {
        this.menuId = menuId;
    }
 
    public Long getParentId() {
        return parentId;
    }
 
    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }
 
    public String getUrl() {
        return url;
    }
 
    public void setUrl(String url) {
        this.url = url == null ? null : url.trim();
    }
   
}

  

4.service层

1
2
3
4
5
6
7
8
9
public R deleteMenu(Long[] ids) {
        int i = sysMenuMapper.deleteMenuIds(ids);
        if (i>0){
            return R.ok();
        }else {
            return R.error("删除失败");
        }
 
    }

  

5.controller层

1
2
3
4
5
@PostMapping("/sys/delete")
    @ResponseBody
    public R del(Long[] ids){
        return  sysMenuService.deleteMenu(ids);
    }

  

6.测试

1
http://localhost:8080/sys/delete?ids=1,2,5

  

 

posted @   Amy清风  阅读(3015)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示