use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestDynamicChoose 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.selectChoose(1, 2);
assertEquals(2, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(182, ((Page<?>) list).getTotal());
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
list = userMapper.selectChoose(1, 2);
assertEquals(2, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(182, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestDynamicIf method testMapper.
/**
* 单个POJO参数情况特殊
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testMapper() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
Map map = new HashMap();
User user = new User();
user.setId(1);
map.put("user", user);
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<User> list = userMapper.selectIf3(user);
assertEquals(2, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(182, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestDynamicIfOrder 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.selectIf2ListAndOrder(Arrays.asList(1, 2), Arrays.asList(3, 4), null);
assertEquals(5, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(179, ((Page<?>) list).getTotal());
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
list = userMapper.selectIf2ListAndOrder(Arrays.asList(1, 2), null, "id");
assertEquals(3, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(181, ((Page<?>) list).getTotal());
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
list = userMapper.selectIf2ListAndOrder(new ArrayList<Integer>(0), null, "name");
assertEquals(18, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestDynamicWhere method testMapperWithStartPage.
@Test
public void testMapperWithStartPage() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第1页,10条内容,默认查询总数count
Map<String, Object> params = new HashMap<String, Object>(2);
params.put("pageNum", 1L);
params.put("pageSize", "100");
PageHelper.startPage(params);
Map<String, Object> where = new HashMap<String, Object>();
where.put("id", 100);
List<User> list = userMapper.selectByWhereMap(new Where(where));
assertEquals(100, list.get(0).getId());
assertEquals(1, list.size());
assertEquals(1, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.
the class TestSelectItems method testSelectColumns.
/**
* 查询自定义列时 - 实际上这个测试由于使用${},并没有起到真正的目的
*/
@Test
public void testSelectColumns() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<User> list = userMapper.selectColumns();
// 1,'Angola','AO'
assertEquals(1, list.get(0).getId());
assertEquals("毕淑儒", list.get(0).getName());
assertEquals("BSR", list.get(0).getPy());
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
list = userMapper.selectColumns("id", "name");
// 1,'Angola','AO'
assertEquals(1, list.get(0).getId());
assertEquals("毕淑儒", list.get(0).getName());
assertNull(list.get(0).getPy());
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
Aggregations