Search in sources :

Example 31 with UserMapper

use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.

the class TestSelectItems method testSelectColumn2.

/**
 * 使用#{}在查询列中进行计算,count查询时需要特殊对待
 */
@Test
public void testSelectColumn2() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        // 获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        List<User> list = userMapper.selectMULId(1);
        // 1,'Angola','AO'
        assertEquals(1, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        // 获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        list = userMapper.selectMULId(5);
        // 1,'Angola','AO'
        assertEquals(5, 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) Test(org.junit.Test)

Example 32 with UserMapper

use of com.github.pagehelper.mapper.UserMapper in project Mybatis-PageHelper by pagehelper.

the class TestIntMax method testCountCache.

/**
 * 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
 */
@Test
public void testCountCache() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        // 获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, Integer.MAX_VALUE);
        List<User> list = userMapper.selectIf(1);
        assertEquals(2, list.get(0).getId());
        assertEquals(182, list.size());
        assertEquals(182, ((Page<?>) list).getTotal());
        // 获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, Integer.MAX_VALUE);
        list = userMapper.selectIf(null);
        assertEquals(1, list.get(0).getId());
        assertEquals(183, 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 33 with UserMapper

use of com.github.pagehelper.mapper.UserMapper 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();
    }
}
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 34 with UserMapper

use of com.github.pagehelper.mapper.UserMapper 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();
    }
}
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 35 with UserMapper

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