use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class PageSizeLessThenOrEqualZeroTest method testWithStartPage.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testWithStartPage() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// pageSize=0,这时候相当于用分页插件求count
PageHelper.startPage(1, 0);
List<User> list = userMapper.selectAll();
PageInfo<User> page = new PageInfo<User>(list);
assertEquals(0, list.size());
assertEquals(183, page.getTotal());
// limit<0的时候同上
PageHelper.startPage(1, -100);
list = userMapper.selectAll();
page = new PageInfo<User>(list);
assertEquals(0, list.size());
assertEquals(183, page.getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class PageTest method testMapperWithStartPageAndPageSizeZeroTrue.
@Test
public void testMapperWithStartPageAndPageSizeZeroTrue() {
SqlSession sqlSession = MybatisReasonableHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第20页,2条内容
// 分页插件会自动改为查询最后一页
PageHelper.startPage(1, 0, true, true, true);
List<User> list = userMapper.selectAll();
PageInfo<User> page = new PageInfo<User>(list);
assertEquals(183, list.size());
assertEquals(1, page.getStartRow());
assertEquals(1, page.getPageNum());
assertEquals(183, page.getTotal());
PageHelper.startPage(1, -1, true, true, true);
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 testMapperWithStartPage.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testMapperWithStartPage() {
SqlSession sqlSession = MybatisReasonableHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第20页,2条内容
// 分页插件会自动改为查询最后一页
PageHelper.startPage(20, 50);
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());
// 获取第-3页,2条内容
// 由于只有7天数据,分页插件会自动改为查询最后一页
PageHelper.startPage(-3, 50);
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 PageRowBoundsTest 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
PageRowBounds pageRowBounds = new PageRowBounds(0, -1);
List<User> list = userMapper.selectAll(pageRowBounds);
assertEquals(183, list.size());
// pageSize<0的时候同上
list = userMapper.selectAll(new PageRowBounds(0, -100));
assertEquals(183, list.size());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class ArgumentsObjTest method testArgumentsObj.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testArgumentsObj() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
UserQueryModel queryModel = new UserQueryModel();
queryModel.setPageNum(1);
queryModel.setPageSize(10);
queryModel.setOrderBy("id desc");
List<User> list = userMapper.selectByQueryModel(queryModel);
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
queryModel.setPageNum(2);
queryModel.setOrderBy(null);
list = userMapper.selectByQueryModel(queryModel);
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
queryModel.setPageNum(3);
queryModel.setPageSize(20);
list = userMapper.selectByQueryModel(queryModel);
assertEquals(20, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
Aggregations