• java根据id批量删除


    1.mapper.xml

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

     

        <!--批量删除-->
      <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层

    int deleteMenuIds(Long[] ids);
    

      

    3.pojo层

    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层

    public R deleteMenu(Long[] ids) {
            int i = sysMenuMapper.deleteMenuIds(ids);
            if (i>0){
                return R.ok();
            }else {
                return R.error("删除失败");
            }
    
        }
    

      

    5.controller层

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

      

    6.测试

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

      

  • 相关阅读:
    Android 视图切换库的使用
    Ext3.4--TreeGridDemo
    Extjs不错的博客
    Extjs学习笔记--(六,选择器)
    Webservice简单案例
    Extjs学习笔记--(五,事件)
    Extjs学习笔记--(四,基本函数介绍)
    Extjs学习笔记--(三,调试技巧)
    SQL集合运算:差集、交集、并集
    Extjs学习笔记--(二)
  • 原文地址:https://www.cnblogs.com/Amywangqing/p/13640686.html
Copyright © 2020-2023  润新知