zoukankan      html  css  js  c++  java
  • Mybatis-Plus通用Mapper CRUD之delete

    mybatis-plus提供了4个删除方法:

    /**
     * 根据 ID 删除
     *
     * @param id 主键ID
     */
    int deleteById(Serializable id);
      
    /**
     * 根据 columnMap 条件,删除记录
     *
     * @param columnMap 表字段 map 对象
     */
    int deleteByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
      
    /**
     * 根据 entity 条件,删除记录
     *
     * @param wrapper 实体对象封装操作类(可以为 null)
     */
    int delete(@Param(Constants.WRAPPER) Wrapper<T> wrapper);
      
    /**
     * 删除(根据ID 批量删除)
     *
     * @param idList 主键ID列表(不能为 null 以及 empty)
     */
    int deleteBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);

    我们先讲下deleteById,deleteByMap,deleteBatchIds方法,delete方法我们放条件构造器里一起讲;

    实例:

    @Test
    public void deleteById(){
        int affectRows = departmentMapper.deleteById(10);
        if(affectRows>0){
             System.out.println("删除成功");
        }else{
             System.out.println("删除失败");
        }
    }
      
    @Test
    public void deleteByMap(){
        Map<String,Object> map=new HashMap<>();
        map.put("name","你好部门5");
        map.put("remark","xxx");
        int affectRows = departmentMapper.deleteByMap(map);
        if(affectRows>0){
             System.out.println("删除成功");
        }else{
             System.out.println("删除失败");
        }
    }
      
    @Test
    public void deleteBatchIds(){
        List<Integer> idList=new LinkedList<>();
        idList.add(11);
        idList.add(12);
        idList.add(13);
        int affectRows =departmentMapper.deleteBatchIds(idList);
        if(affectRows>0){
             System.out.println("删除成功");
        }else{
             System.out.println("删除失败");
        }
      
    }

    ------------------------------------------------------------------------------------------------------------------------------

    作者: java1234_小锋

    出处:https://www.cnblogs.com/java688/p/13522508.html

    版权:本站使用「CC BY 4.0」创作共享协议,转载请在文章明显位置注明作者及出处。

    ------------------------------------------------------------------------------------------------------------------------------

  • 相关阅读:
    网络基础知识
    mysql安装
    docker打包镜像
    python的基础
    python静态属性的理解
    python中的静态方法和类方法
    python类的两种创建方式
    python的继承
    python中time和datetime模块
    python之模块
  • 原文地址:https://www.cnblogs.com/java688/p/13522508.html
Copyright © 2011-2022 走看看