通过id查询
//测试查询
@Test
public void testSelectById(){
//查询单个id
User user=userMapper.selectById(1);
System.out.println(user);
//查询多个id
List<User> users=userMapper.selectBatchIds(Arrays.asList(1,2,3,4));
users.forEach(System.out::println);
}
条件查询(通过map)
//条件查询
@Test
public void testSelectByMap(){
HashMap<String,Object> hash=new HashMap<String,Object>();
//自定义查询
hash.put("name","gem");
hash.put("age",18);
userMapper.selectByMap(hash);
}
分页查询
//分页查询,在网页使用极多
@Test
public void testPage(){
//当前页:1 页面大小:2
Page<User> page=new Page<>(1,2);
userMapper.selectPage(page,null);
page.getRecords().forEach(System.out::println);
System.out.println(page.getTotal());
}
通过id删除
//删除测试
@Test
public void testDeleteById(){
userMapper.deleteById(1804914009888006148L);
}
//通过id批量删除
@Test
public void testDeleteBatchIds(){
userMapper.deleteBatchIds(Arrays.asList(1804892484724183042L,1804914009888006146L));
}
条件删除(通过map)
//通过map删除
@Test
public void testDeleteByMap(){
HashMap<String,Object> hash=new HashMap<String,Object>();
hash.put("name","田先生天下第一帅");
userMapper.deleteByMap(hash);
}