use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.
the class CacheTest 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.selectGreterThanId(10);
assertEquals(10, list.size());
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(2, 10);
list = userMapper.selectGreterThanIdAndNotEquelName(10, "刘睿");
assertEquals(10, list.size());
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(3, 10);
list = userMapper.selectGreterThanIdAndNotEquelName(10, "刘睿");
assertEquals(10, list.size());
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(4, 10);
list = userMapper.selectGreterThanIdAndNotEquelName(10, "刘睿");
assertEquals(10, list.size());
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(5, 10);
list = userMapper.selectGreterThanIdAndNotEquelName(10, "刘睿");
assertEquals(10, list.size());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.
the class TestDynamicIf2 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.selectIf2(1, 2);
assertEquals(3, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(181, ((Page<?>) list).getTotal());
// 获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
list = userMapper.selectIf2(1, null);
assertEquals(2, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(182, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.
the class TestProvider method testUserSelect.
@Test
public void testUserSelect() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
User user = new User();
user.setId(100);
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
PageHelper.startPage(1, 10);
List<Map<String, Object>> userList = userMapper.selectBySelect();
System.out.println(userList.size());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.
the class TestProvider method testSelectSimple.
@Test
public void testSelectSimple() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
PageHelper.startPage(1, 10);
Page<User> list = userMapper.selectSimple("飞");
assertEquals(24, list.get(0).getId());
assertEquals(6, list.size());
assertEquals(6, list.getTotal());
} finally {
sqlSession.close();
}
}
use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.
the class TestProvider method testProvider.
@Test
public void testProvider() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 100);
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
PageHelper.startPage(1, 10);
List<User> list = userMapper.selectByProvider(map);
assertEquals(100, list.get(0).getId());
assertEquals(1, list.size());
assertEquals(1, ((Page<?>) list).getTotal());
map.put("name", "不存在");
PageHelper.startPage(1, 10);
list = userMapper.selectByProvider(map);
assertEquals(0, list.size());
} finally {
sqlSession.close();
}
}
Aggregations