use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.
the class TestDynamicIf2 method testMapperWithStartPage.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testMapperWithStartPage() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectIf2(1, 2);
assertEquals(3, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(181, ((Page<?>) list).getTotal());
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
list = countryMapper.selectIf2(1, null);
assertEquals(2, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(182, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.
the class TestDynamicIfOrder method testMapperWithStartPage.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testMapperWithStartPage() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectIf2ListAndOrder(Arrays.asList(1, 2), Arrays.asList(3, 4), null);
assertEquals(5, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(179, ((Page<?>) list).getTotal());
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
list = countryMapper.selectIf2ListAndOrder(Arrays.asList(1, 2), null, "id");
assertEquals(3, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(181, ((Page<?>) list).getTotal());
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
list = countryMapper.selectIf2ListAndOrder(new ArrayList<Integer>(0), null, "countryname");
assertEquals(2, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.
the class TestDynamicWhere method testMapperWithStartPage.
@Test
public void testMapperWithStartPage() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第1页,10条内容,默认查询总数count
Map<String, Object> params = new HashMap<String, Object>(2);
params.put("pageNum", 1L);
params.put("pageSize", "100");
PageHelper.startPage(params);
Map<String, Object> where = new HashMap<String, Object>();
where.put("id", 100);
List<Country> list = countryMapper.selectByWhereMap(new Where(where));
assertEquals(100, list.get(0).getId());
assertEquals(1, list.size());
assertEquals(1, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.
the class PageSizeZeroTest method testWithRowbounds.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testWithRowbounds() {
SqlSession sqlSession = MybatisPageSizeZeroHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//pageSize=0的时候查询全部结果
List<Country> list = countryMapper.selectAll(new RowBounds(1, 0));
PageInfo<Country> page = new PageInfo<Country>(list);
assertEquals(183, list.size());
assertEquals(183, page.getTotal());
//pageSize=0的时候查询全部结果
PageHelper.startPage(10, 0);
list = countryMapper.selectAll(new RowBounds(1000, 0));
page = new PageInfo<Country>(list);
assertEquals(183, list.size());
assertEquals(183, page.getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.
the class PageSizeZeroTest method testWithStartPage.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testWithStartPage() {
SqlSession sqlSession = MybatisPageSizeZeroHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//pageSize=0的时候查询全部结果
PageHelper.startPage(1, 0);
List<Country> list = countryMapper.selectAll();
PageInfo<Country> page = new PageInfo<Country>(list);
assertEquals(183, list.size());
assertEquals(183, page.getTotal());
//pageSize=0的时候查询全部结果
PageHelper.startPage(10, 0);
list = countryMapper.selectAll();
page = new PageInfo<Country>(list);
assertEquals(183, list.size());
assertEquals(183, page.getTotal());
} finally {
sqlSession.close();
}
}
Aggregations