一、分页查询
1、selectByRowBounds(T record, RowBounds rowBounds)
说明:根据实体属性和RowBounds进行分页查询
案例:
/** * SELECT emp_id,emp_name,emp_salary,emp_age FROM tabple_emp WHERE emp_id = ? AND emp_name = ? */ @Test public void testSelectByRowBounds() { int pageNo = 1; int pageSize = 3; int index = (pageNo - 1) * pageSize; RowBounds rowBounds = new RowBounds(index, pageSize); Employee emp = new Employee(1, "tom", null, null); List<Employee> empList = employeeService.getEmpByRowBounds(emp, rowBounds); empList.forEach(System.out::println); } public List<Employee> getEmpByRowBounds(Employee emp, RowBounds rowBounds) { return employeeMapper.selectByRowBounds(emp, rowBounds); }
通过sql可以看到,并没有使用 limit 关键字,而是把所有的数据查询出来,进行内存的分页。
2、