use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestExecute 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<Map<String, Object>> mapList = userMapper.execute("select * from user");
Assert.assertEquals(10, mapList.size());
mapList = userMapper.execute("select * from user");
Assert.assertEquals(183, mapList.size());
List<User> userList = userMapper.selectAll();
Assert.assertEquals(183, userList.size());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestGroupBy method testGroupBy.
@Test
public void testGroupBy() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第1页,10条内容,默认查询总数count
Page<User> page = PageHelper.startPage(1, 10);
userMapper.selectGroupBy();
// 1,'Angola','AO'
assertEquals(1, page.get(0).getId());
assertEquals(10, page.size());
assertEquals(183, page.getTotal());
PageInfo<User> pageInfo = page.toPageInfo();
System.out.println(pageInfo);
// 获取第2页,10条内容,默认查询总数count
page = PageHelper.startPage(2, 10);
userMapper.selectGroupBy();
// 1,'Angola','AO'
assertEquals(1, page.get(0).getId());
assertEquals(10, page.size());
assertEquals(183, page.getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestDynamicForeach method testMapperWithStartPage2.
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testMapperWithStartPage2() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第1页,10条内容,默认查询总数count
List<Long> idList = new ArrayList<Long>();
idList.add(1L);
idList.add(2L);
idList.add(3L);
PageHelper.startPage(1, 2);
List<User> list = userMapper.selectByIdList2(idList);
assertEquals(1, list.get(0).getId());
assertEquals(2, list.size());
assertEquals(3, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestDynamicForeach 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<Long> idList = new ArrayList<Long>();
idList.add(1L);
idList.add(2L);
idList.add(3L);
PageHelper.startPage(1, 2);
List<User> list = userMapper.selectByIdList(idList);
assertEquals(1, list.get(0).getId());
assertEquals(2, list.size());
assertEquals(3, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestDynamicIfTwoList 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);
List<User> list = userMapper.selectIf2List(Arrays.asList(1, 2), Arrays.asList(3, 4));
assertEquals(5, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(179, ((Page<?>) list).getTotal());
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
list = userMapper.selectIf2List(Arrays.asList(1, 2), null);
assertEquals(3, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(181, ((Page<?>) list).getTotal());
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
list = userMapper.selectIf2List(new ArrayList<Integer>(0), null);
assertEquals(1, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
Aggregations