Search in sources :

Example 26 with UserMapper

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

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

Example 28 with UserMapper

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

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

Example 30 with UserMapper

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