MyBatisPlus---delete删除操作的三种方法

一、根据id删除

1
2
3
4
5
6
7
8
9
10
11
@Test
public void deleteById() {
    int rows = userMapper.deleteById(1351456313578713090L);
    System.out.println("删除条数:" + rows);
}
 
@Test
public void deleteByBatchIds() {
    int rows = userMapper.deleteBatchIds(Arrays.asList(1094592041087729666L, 1351456313578713090L));
    System.out.println("删除条数:" + rows);
}

二、其他普通删除

1
2
3
4
5
6
7
8
@Test
public void deleteByMap() {
    Map<String, Object> map = new HashMap<>();
    map.put("name""张三");
    map.put("age"25);
    int rows = userMapper.deleteByMap(map);
    System.out.println("删除条数:" + rows);
}

三、以条件构造器为参数删除

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Test
public void deleteByWrapper(){
    QueryWrapper wrapper = new QueryWrapper();
    wrapper.eq("name","张三");
    wrapper.eq("age",25);
    int rows = userMapper.delete(wrapper);
    System.out.println("删除条数:" + rows);
}
 
@Test
public void deleteByLambda(){
    LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper();
    wrapper.eq(User::getName,"张三").eq(User::getAge,25);
    int rows = userMapper.delete(wrapper);
    System.out.println("删除条数:" + rows);
}

 

posted on 2023-04-03 16:10  云淡风轻博客  阅读(7311)  评论(0编辑  收藏  举报