zoukankan      html  css  js  c++  java
  • Mybatis-Plus 实战完整学习笔记(八)------delete测试

    1、根据ID删除一个员工deleteById

     1  /**
     2      * 删除客户
     3      *
     4      * @throws SQLException
     5      */
     6     @Test
     7     public void deletedMethod() throws SQLException {
     8 
     9         // 1.根据ID删除一个员工
    10         Integer result = employeeMapper.deleteById(1);
    11 
    12         if (result != null || result > 0) {
    13             logger.info("++++++++++++++++删除成功+++++");
    14         }
    15 
    16     }
    View Code

    2、根据多个ID删除多个员工

     1 /**
     2      * 删除客户
     3      *
     4      * @throws SQLException
     5      */
     6     @Test
     7     public void deletedMethod() throws SQLException {
     8 
     9  
    10        // 2.多个ID删除
    11         List<Integer> idList = new  ArrayList<>();
    12         idList.add(21);
    13         idList.add(20);
    14 
    15         Integer result = employeeMapper.deleteBatchIds(idList);
    16 
    17 
    18         if (result != null || result > 0) {
    19             logger.info("++++++++++++++++删除成功+++++");
    20         }
    21 
    22     }
    View Code

    3、根据map条件删除

     1  /**
     2      * 删除客户
     3      *
     4      * @throws SQLException
     5      */
     6     @Test
     7     public void deletedMethod() throws SQLException {
     8 
     9         // 3.根据map条件删除
    10         Employee employee = employeeMapper.selectById(19);
    11 
    12         Map<String, Object> map = new HashMap<>(16);
    13         map.put("email", employee.getEmail());
    14         map.put("age", employee.getAge());
    15 
    16         Integer result = employeeMapper.deleteByMap(map);
    17 
    18         if (result != null || result > 0) {
    19             logger.info("++++++++++++++++删除成功+++++");
    20         }
    21 
    22     }
    View Code

    4、根据条件构造器删除

     1 /**
     2      * 删除客户
     3      *
     4      * @throws SQLException
     5      */
     6     @Test
     7     public void deletedMethod() throws SQLException {
     8 
     9         // 4.根据条件构造器删除
    10         Integer result = employeeMapper.delete(new QueryWrapper<Employee>()
    11                 .eq("gender", 1));
    12 
    13         if (result != null || result > 0) {
    14             logger.info("++++++++++++++++删除成功+++++");
    15         }
    View Code
  • 相关阅读:
    nginx + keepalived 教程
    mysql 之 获取指定月份天数和指定月份上月天数
    hive 之将sql执行结果输出到文件中
    sql 之 处理一行全为0的记录
    Shell 基础知识
    kettle 调度时出现时区问题,导致数据调出加了8小时
    sql 之按指定分割符取分割符前/后字符串
    Spring Security(二)
    Spring Security(一)
    集成Swagger文档
  • 原文地址:https://www.cnblogs.com/liuyangfirst/p/9738850.html
Copyright © 2011-2022 走看看