Search in sources :

Example 41 with UserMapper

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();
    }
}
Also used : UserMapper(com.github.pagehelper.mapper.UserMapper) User(com.github.pagehelper.model.User) SqlSession(org.apache.ibatis.session.SqlSession) Map(java.util.Map) Test(org.junit.Test)

Example 42 with UserMapper

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();
    }
}
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 43 with UserMapper

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();
    }
}
Also used : UserMapper(com.github.pagehelper.mapper.UserMapper) User(com.github.pagehelper.model.User) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 44 with UserMapper

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();
    }
}
Also used : UserMapper(com.github.pagehelper.mapper.UserMapper) User(com.github.pagehelper.model.User) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 45 with UserMapper

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();
    }
}
Also used : UserMapper(com.github.pagehelper.mapper.UserMapper) User(com.github.pagehelper.model.User) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

UserMapper (com.github.pagehelper.mapper.UserMapper)75 SqlSession (org.apache.ibatis.session.SqlSession)75 Test (org.junit.Test)75 User (com.github.pagehelper.model.User)73 PageInfo (com.github.pagehelper.PageInfo)17 RowBounds (org.apache.ibatis.session.RowBounds)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Map (java.util.Map)3 PageRowBounds (com.github.pagehelper.PageRowBounds)2 UserExample (com.github.pagehelper.model.UserExample)2 BoundSqlInterceptor (com.github.pagehelper.BoundSqlInterceptor)1 ISelect (com.github.pagehelper.ISelect)1 ProviderMethod (com.github.pagehelper.mapper.ProviderMethod)1 UserCode (com.github.pagehelper.model.UserCode)1 UserQueryModel (com.github.pagehelper.model.UserQueryModel)1 CacheKey (org.apache.ibatis.cache.CacheKey)1 BoundSql (org.apache.ibatis.mapping.BoundSql)1