删除专栏
文章目录
@Component
public class UserMapperDelTest extends MybatisPlusSamplesChapter1ApplicationTests {
@Resource
private UserMapper userMapper;
/**
* 根据 ID 删除
*/
@Test
public void delById() {
int rows = userMapper.deleteById(1094592041087729666L);
System.out.println("删除条数:" + rows);
}
/**
* 根据 columnMap 条件,删除记录
*/
@Test
public void delByMap() {
HashMap<String, Object> columnMap = new HashMap<>();
columnMap.put("name", "向后");
columnMap.put("age", 25);
int rows = userMapper.deleteByMap(columnMap);
System.out.println("删除条数:" + rows);
}
/**
* 删除(根据ID 批量删除)
* <p>
* 主键ID列表(不能为 null 以及 empty)
*/
@Test
public void deleteBatchIds() {
int rows = userMapper.deleteBatchIds(Arrays.asList(109459204108772966L, 1088250446457389058L, 1088250446457389059L));
System.out.println("删除条数:" + rows);
}
@Test
public void deleteByWrapper() {
LambdaQueryWrapper<User> lambdaQuery = Wrappers.<User>lambdaQuery();
lambdaQuery.eq(User::getAge, 27)
.gt(User::getAge, 41);
int rows = userMapper.delete(lambdaQuery);
System.out.println("删除条数:" + rows);
}
}