use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.
the class RowBoundsTest method testWithRowboundsAndCountTrue.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testWithRowboundsAndCountTrue() {
SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//limit=0,这时候相当于用分页插件求count,但是前提必须是配置rounbounds方式求count,否则都是-1
//这里由于没有配置,应该都是-1
List<Country> list = countryMapper.selectAll(new RowBounds(1, -1));
PageInfo<Country> page = new PageInfo<Country>(list);
assertEquals(0, list.size());
assertEquals(183, page.getTotal());
//pageSize<0的时候同上
list = countryMapper.selectAll(new RowBounds(1, -100));
page = new PageInfo<Country>(list);
assertEquals(0, list.size());
assertEquals(183, page.getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.
the class TestParameterNone 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.selectAll();
assertEquals(1, 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 TestProvider method testProvider.
@Test
public void testProvider() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 100);
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectByProvider(map);
assertEquals(100, list.get(0).getId());
assertEquals(1, list.size());
assertEquals(1, ((Page<?>) list).getTotal());
map.put("countryname", "天朝");
PageHelper.startPage(1, 10);
list = countryMapper.selectByProvider(map);
assertEquals(0, list.size());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.
the class TestProvider method testCountryProvider.
@Test
public void testCountryProvider() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
Country country = new Country();
country.setId(100);
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectByCountryProvider(country);
assertEquals(100, list.get(0).getId());
assertEquals(1, list.size());
assertEquals(1, ((Page<?>) list).getTotal());
country.setCountryname("天朝");
PageHelper.startPage(1, 10);
list = countryMapper.selectByCountryProvider(country);
assertEquals(0, list.size());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.
the class TestExists method testExists.
/**
* union的count查询sql特殊
*/
@Test
public void testExists() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectExists();
assertEquals(101, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(83, ((Page<?>) list).getTotal());
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(2, 10);
list = countryMapper.selectExists();
assertEquals(111, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(83, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
Aggregations