use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class TestIntMax method testCountCache.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testCountCache() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, Integer.MAX_VALUE);
List<Country> list = countryMapper.selectIf(1);
assertEquals(2, list.get(0).getId());
assertEquals(182, list.size());
assertEquals(182, ((Page<?>) list).getTotal());
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, Integer.MAX_VALUE);
list = countryMapper.selectIf(null);
assertEquals(1, list.get(0).getId());
assertEquals(183, 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 TestNamespaceMap method testMapperWithStartPage.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testMapperWithStartPage() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
Map<String, Object> map = new HashMap<String, Object>();
map.put("countryname", "c");
List<Country> list = sqlSession.selectList("selectLike", map);
assertEquals(30, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(39, ((Page<?>) list).getTotal());
PageHelper.startPage(1, 10);
map.put("countryname", "China");
map.put("countrycode", "CN");
list = sqlSession.selectList("selectByMap", map);
assertEquals(35, list.get(0).getId());
assertEquals(1, list.size());
assertEquals(1, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class CacheTest 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.selectGreterThanId(10);
assertEquals(10, list.size());
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(2, 10);
list = countryMapper.selectGreterThanIdAndNotEquelContryname(10, "china");
assertEquals(10, list.size());
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(3, 10);
list = countryMapper.selectGreterThanIdAndNotEquelContryname(10, "china");
assertEquals(10, list.size());
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(4, 10);
list = countryMapper.selectGreterThanIdAndNotEquelContryname(10, "china");
assertEquals(10, list.size());
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(5, 10);
list = countryMapper.selectGreterThanIdAndNotEquelContryname(10, "china");
assertEquals(10, list.size());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class SecondCacheTest method test2.
@Test
public void test2() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectGreterThanId(10);
assertEquals(10, list.size());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class TestSelectItems method testSelectColumns.
/**
* 查询自定义列时 - 实际上这个测试由于使用${},并没有起到真正的目的
*/
@Test
public void testSelectColumns() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectColumns();
//1,'Angola','AO'
assertEquals(1, list.get(0).getId());
assertEquals("Angola", list.get(0).getCountryname());
assertEquals("AO", list.get(0).getCountrycode());
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
list = countryMapper.selectColumns("id", "countryname");
//1,'Angola','AO'
assertEquals(1, list.get(0).getId());
assertEquals("Angola", list.get(0).getCountryname());
assertNull(list.get(0).getCountrycode());
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
Aggregations