use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.
the class RowBoundsTest method testWithRowboundsAndCountTrue.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testWithRowboundsAndCountTrue() {
SqlSession sqlSession = RowBoundsHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// limit=0,这时候相当于用分页插件求count,但是前提必须是配置rounbounds方式求count,否则都是-1
// 这里由于没有配置,应该都是-1
List<User> list = userMapper.selectAll(new RowBounds(0, -1));
assertEquals(183, list.size());
// pageSize<0的时候同上
list = userMapper.selectAll(new RowBounds(0, -100));
assertEquals(183, list.size());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.
the class ArgumentsMapTest method testArgumentsMap.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testArgumentsMap() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
List<User> list = userMapper.selectByPageNumSizeOrderBy(1, 10, "id desc");
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
list = userMapper.selectByPageNumSize(2, 10);
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
list = userMapper.selectByPageNumSize(3, 20);
assertEquals(20, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.
the class CloseableTest method testCloseable.
@Test
public void testCloseable() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
// 下面注释代码只能在jdk7+中进行测试
// try(Page<Object> page = PageHelper.startPage(1, 10)) {
// int a = 10/0;
// userMapper.selectAll();
// Assert.fail();
// } catch (Exception e){
// e.printStackTrace();
// }
List<User> user = userMapper.selectAll();
Assert.assertEquals(183, user.size());
sqlSession.close();
}
use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.
the class CountColumnTest method testMapperWithStartPage.
@Test
public void testMapperWithStartPage() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10).countColumn("id");
User user = new User();
user.setName("刘");
List<User> list = userMapper.selectLike(user);
assertEquals(78, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(15, ((Page<?>) list).getTotal());
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(2, 10);
list = userMapper.selectLike(user);
assertEquals(88, list.get(0).getId());
assertEquals(5, list.size());
assertEquals(15, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.
the class PageSizeZeroTest method testWithStartPage.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testWithStartPage() {
SqlSession sqlSession = MybatisPageSizeZeroHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// pageSize=0的时候查询全部结果
PageHelper.startPage(1, 0);
List<User> list = userMapper.selectAll();
PageInfo<User> page = new PageInfo<User>(list);
assertEquals(183, list.size());
assertEquals(183, page.getTotal());
// pageSize=0的时候查询全部结果
PageHelper.startPage(10, 0);
list = userMapper.selectAll();
page = new PageInfo<User>(list);
assertEquals(183, list.size());
assertEquals(183, page.getTotal());
} finally {
sqlSession.close();
}
}
Aggregations