Mybatis分页
2020-04-15 本文已影响0人
小杨小杨神采飞杨
分页
使用limit实现分页
语法:
select * from xxx limit startIndex,pageNumber;
从指定下标开始查询,查询pageNumber条数据

定义方法,使用Map集合

配置xml

测试代码

结果
使用RowBounds
以面向对象的思想,实现分页
第一步,创建方法

第二步,在xml中配置sql,此时不需要再sql中使用limit进行分页

第三步,进行测试
@Test
public void test04() {
SqlSession sqlSession = mybatisUtil.getSqlSession();
stuMapper mapper = sqlSession.getMapper(stuMapper.class);
RowBounds rowBounds = new RowBounds(1,2); //实例化RowBounds,设置分页信息
List<student> students = sqlSession.selectList("cn.yzx.mapper.stuMapper.getUserByRowBounds", null, rowBounds); //使用sqlSession的方法进行分页查询
for (student student : students) {
System.out.println(student);
}
sqlSession.close();
}

可见,并没有使用limit进行分页