use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class TestSelectItems method testSelectColumn2.
/**
* 使用#{}在查询列中进行计算,count查询时需要特殊对待
*/
@Test
public void testSelectColumn2() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectMULId(1);
//1,'Angola','AO'
assertEquals(1, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
list = countryMapper.selectMULId(5);
//1,'Angola','AO'
assertEquals(5, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class OffsetTest method testOffset.
@Test
public void testOffset() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
PageHelper.startPage(1, 6);
List<Country> list = countryMapper.selectAll();
assertEquals(6, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
PageHelper.offsetPage(6, 20);
list = countryMapper.selectAll();
PageInfo<Country> pageInfo = new PageInfo<Country>(list);
System.out.println(pageInfo.toString());
assertEquals(2, ((Page<?>) list).getPageNum());
assertEquals(20, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class OffsetTest method testPageNum.
@Test
public void testPageNum() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
PageHelper.offsetPage(5, 5);
List<Country> list = countryMapper.selectAll();
assertEquals(2, ((Page<?>) list).getPageNum());
assertEquals(5, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
PageHelper.offsetPage(15, 5);
list = countryMapper.selectAll();
assertEquals(4, ((Page<?>) list).getPageNum());
assertEquals(5, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class PageInfoTest method testPageSize10.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testPageSize10() {
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);
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(8, page.getLastPage());
assertEquals(true, page.isIsFirstPage());
assertEquals(false, page.isIsLastPage());
assertEquals(false, page.isHasPreviousPage());
assertEquals(true, page.isHasNextPage());
//获取第2页,10条内容,默认查询总数count
PageHelper.startPage(2, 10);
list = countryMapper.selectAll();
page = new PageInfo<Country>(list);
assertEquals(2, page.getPageNum());
assertEquals(10, page.getPageSize());
assertEquals(11, page.getStartRow());
assertEquals(20, page.getEndRow());
assertEquals(183, page.getTotal());
assertEquals(19, page.getPages());
assertEquals(1, page.getFirstPage());
assertEquals(8, page.getLastPage());
assertEquals(false, page.isIsFirstPage());
assertEquals(false, page.isIsLastPage());
assertEquals(true, page.isHasPreviousPage());
assertEquals(true, page.isHasNextPage());
//获取第19页,10条内容,默认查询总数count
PageHelper.startPage(19, 10);
list = countryMapper.selectAll();
page = new PageInfo<Country>(list);
assertEquals(19, page.getPageNum());
assertEquals(10, page.getPageSize());
assertEquals(181, page.getStartRow());
assertEquals(183, page.getEndRow());
assertEquals(183, page.getTotal());
assertEquals(19, page.getPages());
assertEquals(12, page.getFirstPage());
assertEquals(19, page.getLastPage());
assertEquals(false, page.isIsFirstPage());
assertEquals(true, page.isIsLastPage());
assertEquals(true, page.isHasPreviousPage());
assertEquals(false, page.isHasNextPage());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class PageInfoTest method testPageSize50.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testPageSize50() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第1页,50条内容,默认查询总数count
PageHelper.startPage(1, 50);
List<Country> list = countryMapper.selectAll();
PageInfo<Country> page = new PageInfo<Country>(list);
assertEquals(1, page.getPageNum());
assertEquals(50, page.getPageSize());
assertEquals(1, page.getStartRow());
assertEquals(50, page.getEndRow());
assertEquals(183, page.getTotal());
assertEquals(4, page.getPages());
assertEquals(1, page.getFirstPage());
assertEquals(4, 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);
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(4, page.getLastPage());
assertEquals(false, page.isIsFirstPage());
assertEquals(false, page.isIsLastPage());
assertEquals(true, page.isHasPreviousPage());
assertEquals(true, page.isHasNextPage());
//获取第3页,50条内容,默认查询总数count
PageHelper.startPage(3, 50);
list = countryMapper.selectAll();
page = new PageInfo<Country>(list);
assertEquals(3, page.getPageNum());
assertEquals(50, page.getPageSize());
assertEquals(101, page.getStartRow());
assertEquals(150, page.getEndRow());
assertEquals(183, page.getTotal());
assertEquals(4, page.getPages());
assertEquals(1, page.getFirstPage());
assertEquals(4, page.getLastPage());
assertEquals(false, page.isIsFirstPage());
assertEquals(false, page.isIsLastPage());
assertEquals(true, page.isHasPreviousPage());
assertEquals(true, page.isHasNextPage());
//获取第4页,50条内容,默认查询总数count
PageHelper.startPage(4, 50);
list = countryMapper.selectAll();
page = new PageInfo<Country>(list);
assertEquals(4, page.getPageNum());
assertEquals(50, page.getPageSize());
assertEquals(151, page.getStartRow());
assertEquals(183, page.getEndRow());
assertEquals(183, page.getTotal());
assertEquals(4, page.getPages());
assertEquals(1, page.getFirstPage());
assertEquals(4, page.getLastPage());
assertEquals(false, page.isIsFirstPage());
assertEquals(true, page.isIsLastPage());
assertEquals(true, page.isHasPreviousPage());
assertEquals(false, page.isHasNextPage());
} finally {
sqlSession.close();
}
}
Aggregations