Mybatis-Plus 实战完整学习笔记(十一)------条件构造器删除,修改,conditon

1、修改功能--其他过滤方式跟select一样

 1 /**
 2      * 修改条件构造器
 3      * @throws SQLException
 4      */
 5     @Test
 6     public void selectUpdate() throws SQLException {
 7 
 8         Employee employee = new Employee();
 9         employee.setGender(1);
10 
11         // 添加过滤条件
12         Integer result = employeeMapper.update(employee,new UpdateWrapper<>());
13 
14 
15         if (result>0) {
16             logger.info("++ 更新成功+++++" + result);
17         }
18 
19     }
View Code

2、删除功能

 1  /**
 2      * 删除条件
 3      * @throws SQLException
 4      */
 5     @Test
 6     public void deleted() throws SQLException {
 7 
 8 
 9         Employee employee = new Employee();
10         employee.setId(1);
11 
12         // 删除过滤条件
13         Integer result = employeeMapper.delete(new QueryWrapper<>());
14 
15         if (result>0) {
16             logger.info("++ 删除成功+++++" + result);
17         }
18 
19     }
View Code

3、Condition跟QueryWrapper一样

 1  /**
 2      * Condition用法
 3      *
 4      * @throws SQLException
 5      */
 6     @Test
 7     public void selectCondition() throws SQLException {
 8 
 9         //Condition用法
10         QueryWrapper condition = Condition.create().eq("age", "20");
11 
12         List employeeList = employeeMapper.selectList(condition);
13 
14 
15         if (!employeeList.isEmpty()) {
16             logger.info("++条件构造器查询员工信息+++++" + gson.toJson(employeeList));
17         }
18 
19     }
View Code

 

posted @ 2018-10-03 17:51  北极的大企鹅  阅读(4757)  评论(0编辑  收藏  举报
阅读 - 79万