use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestParameterList method testMapperWithStartPage.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testMapperWithStartPage() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第1页,10条内容,默认查询总数count
List<Integer> paList = new ArrayList<Integer>();
paList.add(1);
paList.add(2);
PageHelper.startPage(1, 10);
List<User> list = userMapper.selectAllOrderByList(paList);
assertEquals(3, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(181, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class PageInfoTest method testNavigatePages.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testNavigatePages() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<User> list = userMapper.selectAll();
PageInfo<User> page = new PageInfo<User>(list, 20);
assertEquals(1, page.getPageNum());
assertEquals(10, page.getPageSize());
assertEquals(1, page.getStartRow());
assertEquals(10, page.getEndRow());
assertEquals(183, page.getTotal());
assertEquals(19, page.getPages());
assertEquals(true, page.isIsFirstPage());
assertEquals(false, page.isIsLastPage());
assertEquals(false, page.isHasPreviousPage());
assertEquals(true, page.isHasNextPage());
// 获取第2页,50条内容,默认查询总数count
PageHelper.startPage(2, 50);
list = userMapper.selectAll();
page = new PageInfo<User>(list, 2);
assertEquals(2, page.getPageNum());
assertEquals(50, page.getPageSize());
assertEquals(51, page.getStartRow());
assertEquals(100, page.getEndRow());
assertEquals(183, page.getTotal());
assertEquals(4, page.getPages());
assertEquals(false, page.isIsFirstPage());
assertEquals(false, page.isIsLastPage());
assertEquals(true, page.isHasPreviousPage());
assertEquals(true, page.isHasNextPage());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestDistinct method test.
@Test
public void test() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<User> list = userMapper.selectDistinct();
assertEquals(10, list.size());
assertEquals(58, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestLike method testMapperWithStartPage.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testMapperWithStartPage() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
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.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestLike method testMapperWithStartPage_OrderBy.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testMapperWithStartPage_OrderBy() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第1页,10条内容,默认查询总数count
PageHelper.orderBy("id desc");
User user = new User();
user.setName("刘");
List<User> list = userMapper.selectLike(user);
assertEquals(92, list.get(0).getId());
assertEquals(15, list.size());
assertEquals(15, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
Aggregations