查询所有信息
userMapper.selectList(null);
根据id查询
userMapper.selectById(1269963192646320129L);
根据id批量查询
userMapper.selectBatchIds(Arrays.asList(1, 2, 3));
条件查询
map.put("name", "Jone");
map.put("age", 18);
userMapper.selectByMap(map);
分页查询的实现
添加分页插件
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
在使用的方法中new一个page对象
调用mp中的分页查询方法
所有数据都封装在page对象中
// 1. new 一个page
// 传入两个参数 : 当前页和每页记录数
Page<User> page = new Page<>(1, 3);
// 调用分页查询的方法
// 调用mp分页查询底层封装
// 把分页所有数据封装到page对象中
userMapper.selectPage(page, null);
// 通过page对象获取分页数据
System.out.println(page.getCurrent());//获取当前页
System.out.println(page.getRecords());//获取每页数据list集合
System.out.println(page.getSize());//每页显示记录数
System.out.println(page.getTotal());//总记录数
System.out.println(page.getPages());//获取总页数
System.out.println(page.hasNext());//是否有下一页
System.out.println(page.hasPrevious());//是否有上一页