1,通过id查询
userMapper.selectById();
2,同时查询多个id数据
for (User id : userMapper.selectBatchIds(Arrays.asList(1L, 2L, 3L))) {
System.out.println(id);
}
3,分页查询
1,添加插件
@Bean public PaginationInterceptor paginationInterceptor() { return new PaginationInterceptor(); }
2,编写分页代码
直接new page对象,传入两个参数:当前页数和每页显示的条数;
3,调用mp方法实现分页查询;
@Test void selectByPage() { Page<User> page = new Page<>(1,2); IPage<User> userIPage = userMapper.selectPage(page, null); System.out.println("分页 :"+userIPage); long current = userIPage.getCurrent(); System.out.println("current : "+current); }