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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM