其他分享
首页 > 其他分享> > 通用Mapper(六)分页查询

通用Mapper(六)分页查询

作者:互联网

一、分页查询

  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、

 

标签:Mapper,分页,pageSize,int,rowBounds,查询,emp,Employee,RowBounds
来源: https://www.cnblogs.com/niujifei/p/15269957.html