use of com.github.pagehelper.PageInfo in project Mybatis-PageHelper by pagehelper.
the class PageInfoTest method testNavigatePages.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testNavigatePages() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectAll();
PageInfo<Country> page = new PageInfo<Country>(list, 20);
assertEquals(1, page.getPageNum());
assertEquals(10, page.getPageSize());
assertEquals(1, page.getStartRow());
assertEquals(10, page.getEndRow());
assertEquals(183, page.getTotal());
assertEquals(19, page.getPages());
assertEquals(1, page.getFirstPage());
assertEquals(19, page.getLastPage());
assertEquals(true, page.isIsFirstPage());
assertEquals(false, page.isIsLastPage());
assertEquals(false, page.isHasPreviousPage());
assertEquals(true, page.isHasNextPage());
//获取第2页,50条内容,默认查询总数count
PageHelper.startPage(2, 50);
list = countryMapper.selectAll();
page = new PageInfo<Country>(list, 2);
assertEquals(2, page.getPageNum());
assertEquals(50, page.getPageSize());
assertEquals(51, page.getStartRow());
assertEquals(100, page.getEndRow());
assertEquals(183, page.getTotal());
assertEquals(4, page.getPages());
assertEquals(1, page.getFirstPage());
assertEquals(2, page.getLastPage());
assertEquals(false, page.isIsFirstPage());
assertEquals(false, page.isIsLastPage());
assertEquals(true, page.isHasPreviousPage());
assertEquals(true, page.isHasNextPage());
} finally {
sqlSession.close();
}
}
Aggregations