分页的实现的几种方法

1.思考:为什么要实现分页

数据量太大的时候为了减少数据的处理量

2.具体实现代码依赖

1.sql语句实现分页

SELECT * FROM ljqdb.`user` LIMIT num1,num2;

从num1开始查 查num2个
num1=startIndex  num2=Pagesize

Mapper.xml的编写 




 

 Mapper以及测试类的编写



    List getUserByLimit(Map map);


测试类:
 SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        Map map = new HashMap<>();
        map.put("startIndex",1);
        map.put("pageSize",3);
        List userByLimit = mapper.getUserByLimit(map);
        for (User user : userByLimit) {
            System.out.println(user);
        }
        sqlSession.close();

2.RowBounds 

UserMapper的编写

/**
     * Gets user by row brunds.
     *
     * @return the user by row brunds
     */
    List getUserByRowBrunds();

UserMapper.xml的编写

 

测试类的编写

public void gerUserByRowBounds(){

        SqlSession sqlSession = MybatisUtils.getSqlSession();
        RowBounds rowBounds = new RowBounds(1, 4);
        List userList = sqlSession.selectList("dao.UserMapper.getUserByRowBrunds", null, rowBounds);
        for (User user : userList ) {
            System.out.println(user);
        }

        sqlSession.close();

    }

3.Mybatis分页插件 

MyBatis 分页插件 PageHelperhttps://pagehelper.github.io/

你可能感兴趣的:(Mybatis,and,Plus,java,mybatis)