一,基本查询
//测试查询
@Test
public void testselectById(){
TUser tUser = tUserMapper.selectById(1L);
System.out.println(tUser);
}
// 测试批量查询!
@Test
public void testselectByBatchid(){
List<TUser> users = tUserMapper.selectBatchIds (Arrays. asList(1, 2, 3));
users. forEach (System.out::println);
}
//按条件查询之一使用map操作
@Test
public void testselectByBatchIds() {
HashMap<String, Object> map = new HashMap<String, Object>();
//自定义要查询
map.put("username", "zl222");
List<TUser> tUsers = tUserMapper.selectByMap (map);
tUsers.forEach (System.out::println);
}
二,分页查询
1,引入MyBatisPlus插件
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
2,分页查询
@Test
public void testPage(){
//第一个参数:当前页数
//第二个参数:显示数据条数
Page<TUser> tUserPage = new Page<>(1,5);
IPage<TUser> tUserIPage = tUserMapper.selectPage(tUserPage, null);
tUserIPage.getRecords().forEach(System.out::println);
}