Search in sources :

Example 6 with User

use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.

the class RowBoundsTest 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
        List<User> list = userMapper.selectAll(new RowBounds(0, -1));
        assertEquals(183, list.size());
        // pageSize<0的时候同上
        list = userMapper.selectAll(new RowBounds(0, -100));
        assertEquals(183, list.size());
    } finally {
        sqlSession.close();
    }
}
Also used : UserMapper(com.github.pagehelper.mapper.UserMapper) User(com.github.pagehelper.model.User) SqlSession(org.apache.ibatis.session.SqlSession) RowBounds(org.apache.ibatis.session.RowBounds) Test(org.junit.Test)

Example 7 with User

use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.

the class ArgumentsMapTest method testArgumentsMap.

/**
 * 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
 */
@Test
public void testArgumentsMap() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        List<User> list = userMapper.selectByPageNumSizeOrderBy(1, 10, "id desc");
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        list = userMapper.selectByPageNumSize(2, 10);
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        list = userMapper.selectByPageNumSize(3, 20);
        assertEquals(20, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}
Also used : UserMapper(com.github.pagehelper.mapper.UserMapper) User(com.github.pagehelper.model.User) SqlSession(org.apache.ibatis.session.SqlSession) Test(org.junit.Test)

Example 8 with User

use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.

the class CloseableTest method testCloseable.

@Test
public void testCloseable() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    // 下面注释代码只能在jdk7+中进行测试
    // try(Page<Object> page = PageHelper.startPage(1, 10)) {
    // int a = 10/0;
    // userMapper.selectAll();
    // Assert.fail();
    // } catch (Exception e){
    // e.printStackTrace();
    // }
    List<User> user = userMapper.selectAll();
    Assert.assertEquals(183, user.size());
    sqlSession.close();
}
Also used : UserMapper(com.github.pagehelper.mapper.UserMapper) User(com.github.pagehelper.model.User) SqlSession(org.apache.ibatis.session.SqlSession) Test(org.junit.Test)

Example 9 with User

use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.

the class CountColumnTest method testMapperWithStartPage.

@Test
public void testMapperWithStartPage() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        // 获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10).countColumn("id");
        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();
    }
}
Also used : UserMapper(com.github.pagehelper.mapper.UserMapper) User(com.github.pagehelper.model.User) SqlSession(org.apache.ibatis.session.SqlSession) Test(org.junit.Test)

Example 10 with User

use of com.github.pagehelper.model.User in project Mybatis-PageHelper by pagehelper.

the class PageSizeZeroTest method testWithStartPage.

/**
 * 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
 */
@Test
public void testWithStartPage() {
    SqlSession sqlSession = MybatisPageSizeZeroHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        // pageSize=0的时候查询全部结果
        PageHelper.startPage(1, 0);
        List<User> list = userMapper.selectAll();
        PageInfo<User> page = new PageInfo<User>(list);
        assertEquals(183, list.size());
        assertEquals(183, page.getTotal());
        // pageSize=0的时候查询全部结果
        PageHelper.startPage(10, 0);
        list = userMapper.selectAll();
        page = new PageInfo<User>(list);
        assertEquals(183, list.size());
        assertEquals(183, page.getTotal());
    } finally {
        sqlSession.close();
    }
}
Also used : UserMapper(com.github.pagehelper.mapper.UserMapper) PageInfo(com.github.pagehelper.PageInfo) User(com.github.pagehelper.model.User) SqlSession(org.apache.ibatis.session.SqlSession) Test(org.junit.Test)

Aggregations

User (com.github.pagehelper.model.User)87 SqlSession (org.apache.ibatis.session.SqlSession)87 Test (org.junit.Test)87 UserMapper (com.github.pagehelper.mapper.UserMapper)73 PageInfo (com.github.pagehelper.PageInfo)17 RowBounds (org.apache.ibatis.session.RowBounds)14 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)5 PageRowBounds (com.github.pagehelper.PageRowBounds)4 Map (java.util.Map)3 UserExample (com.github.pagehelper.model.UserExample)2 ISelect (com.github.pagehelper.ISelect)1 UserQueryModel (com.github.pagehelper.model.UserQueryModel)1