use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class PageTest method testMapperWithStartPageAndReasonableFalse.
@Test
public void testMapperWithStartPageAndReasonableFalse() {
SqlSession sqlSession = MybatisReasonableHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第20页,2条内容
// 分页插件会自动改为查询最后一页
PageHelper.startPage(20, 50, true, false, false);
List<User> list = userMapper.selectAll();
PageInfo<User> page = new PageInfo<User>(list);
assertEquals(0, list.size());
assertEquals(0, page.getStartRow());
assertEquals(20, page.getPageNum());
assertEquals(183, page.getTotal());
PageHelper.startPage(4, 50, true, false, false);
list = userMapper.selectAll();
page = new PageInfo<User>(list);
assertEquals(33, list.size());
assertEquals(151, page.getStartRow());
assertEquals(4, page.getPageNum());
assertEquals(183, page.getTotal());
PageHelper.startPage(-1, 50, true, false, false);
list = userMapper.selectAll();
page = new PageInfo<User>(list);
assertEquals(0, list.size());
assertEquals(0, page.getStartRow());
assertEquals(-1, page.getPageNum());
assertEquals(183, page.getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class PageTest method testMapperWithStartPageAndPageSizeZeroFalse.
@Test
public void testMapperWithStartPageAndPageSizeZeroFalse() {
SqlSession sqlSession = MybatisReasonableHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第20页,2条内容
// 分页插件会自动改为查询最后一页
PageHelper.startPage(1, 0, true, true, false);
List<User> list = userMapper.selectAll();
PageInfo<User> page = new PageInfo<User>(list);
assertEquals(0, list.size());
assertEquals(0, page.getStartRow());
assertEquals(1, page.getPageNum());
assertEquals(183, page.getTotal());
PageHelper.startPage(1, Integer.MAX_VALUE, true, true, false);
list = userMapper.selectAll();
page = new PageInfo<User>(list);
assertEquals(183, list.size());
assertEquals(1, page.getStartRow());
assertEquals(1, page.getPageNum());
assertEquals(183, page.getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class PageTest method testMapperWithStartPageAndReasonableTrue.
@Test
public void testMapperWithStartPageAndReasonableTrue() {
SqlSession sqlSession = MybatisReasonableHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第20页,2条内容
// 分页插件会自动改为查询最后一页
PageHelper.startPage(20, 50, true, true, false);
List<User> list = userMapper.selectAll();
PageInfo<User> page = new PageInfo<User>(list);
assertEquals(33, list.size());
assertEquals(151, page.getStartRow());
assertEquals(4, page.getPageNum());
assertEquals(183, page.getTotal());
PageHelper.startPage(4, 50, true, true, false);
list = userMapper.selectAll();
page = new PageInfo<User>(list);
assertEquals(33, list.size());
assertEquals(151, page.getStartRow());
assertEquals(4, page.getPageNum());
assertEquals(183, page.getTotal());
PageHelper.startPage(-1, 50, true, true, false);
list = userMapper.selectAll();
page = new PageInfo<User>(list);
assertEquals(50, list.size());
assertEquals(1, page.getStartRow());
assertEquals(1, page.getPageNum());
assertEquals(183, page.getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper 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.mapper.UserMapper 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();
}
}
Aggregations