use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class BasicTest method testNamespace1.
@Test
public void testNamespace1() {
SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession();
try {
Map<String, Object> map = new HashMap<String, Object>();
Country country = new Country();
country.setCountryname("China");
map.put("country", country);
//同时测试不可变Map
map = Collections.unmodifiableMap(map);
List<Country> list = sqlSession.selectList("select1", map, new RowBounds(1, 10));
assertEquals(1, list.size());
//判断查询结果的位置是否正确
assertEquals(35, list.get(0).getId());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class BasicTest method testNamespace2.
@Test
public void testNamespace2() {
SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession();
try {
Map<String, Object> map = new HashMap<String, Object>();
Country country = new Country();
country.setCountryname("China");
map.put("country", country);
PageHelper.startPage(1, 10);
List<Country> list = sqlSession.selectList("select1", map);
assertEquals(1, list.size());
//判断查询结果的位置是否正确
assertEquals(35, list.get(0).getId());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class PageSizeLessThenOrEqualZeroTest method testWithStartPage.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testWithStartPage() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//pageSize=0,这时候相当于用分页插件求count
PageHelper.startPage(1, 0);
List<Country> list = countryMapper.selectAll();
PageInfo<Country> page = new PageInfo<Country>(list);
assertEquals(183, list.size());
assertEquals(183, page.getTotal());
//limit<0的时候同上
PageHelper.startPage(1, -100);
list = countryMapper.selectAll();
page = new PageInfo<Country>(list);
assertEquals(0, list.size());
assertEquals(183, page.getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.Country in project Mybatis-PageHelper by pagehelper.
the class PageSizeLessThenOrEqualZeroTest method testWithRowbounds.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testWithRowbounds() {
//注意这里是MybatisRowBoundsHelper,会求count
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//limit=0,这时候相当于用分页插件求count,但是前提必须是配置rounbounds方式求count,否则都是-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());
//limit<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.model.Country in project Mybatis-PageHelper by pagehelper.
the class PageTest method testMapperWithStartPage.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testMapperWithStartPage() {
SqlSession sqlSession = MybatisReasonableHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第20页,2条内容
//分页插件会自动改为查询最后一页
PageHelper.startPage(20, 50);
List<Country> list = countryMapper.selectAll();
PageInfo<Country> page = new PageInfo<Country>(list);
assertEquals(33, list.size());
assertEquals(151, page.getStartRow());
assertEquals(4, page.getPageNum());
assertEquals(183, page.getTotal());
//获取第-3页,2条内容
//由于只有7天数据,分页插件会自动改为查询最后一页
PageHelper.startPage(-3, 50);
list = countryMapper.selectAll();
page = new PageInfo<Country>(list);
assertEquals(50, list.size());
assertEquals(1, page.getStartRow());
assertEquals(1, page.getPageNum());
assertEquals(183, page.getTotal());
} finally {
sqlSession.close();
}
}
Aggregations