Search in sources :

Example 66 with User

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

the class TestParameterMap method testMapperWithStartPage.

/**
 * 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
 */
@Test
public void testMapperWithStartPage() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        // 获取第1页,10条内容,默认查询总数count
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("order1", 1);
        map.put("order2", 2);
        map.put("tableName", "user");
        PageHelper.startPage(1, 10);
        List<User> list = userMapper.selectAllOrderByMap(map);
        assertEquals(3, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(181, ((Page<?>) list).getTotal());
        map.put("tableName", "user a");
        PageHelper.startPage(1, 10);
        list = userMapper.selectAllOrderByMap(map);
        assertEquals(3, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(181, ((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 67 with User

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

the class TestParameterOne 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(1);
        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 68 with User

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

the class TestExample method testNull.

@Test
public void testNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        PageHelper.startPage(1, 20);
        List<User> list = userMapper.selectByExample(null);
        assertEquals(1, list.get(0).getId());
        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 69 with User

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

the class TestExample method testGreaterThan.

@Test
public void testGreaterThan() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        UserExample example = new UserExample();
        example.createCriteria().andIdGreaterThan(100);
        PageHelper.startPage(1, 20);
        List<User> list = userMapper.selectByExample(example);
        assertEquals(101, list.get(0).getId());
        assertEquals(20, list.size());
        assertEquals(83, ((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) UserExample(com.github.pagehelper.model.UserExample) Test(org.junit.Test)

Example 70 with User

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

the class TestExample method testInList.

@Test
public void testInList() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        UserExample example = new UserExample();
        example.createCriteria().andIdIn(Arrays.asList(1, 2, 3, 4, 5));
        PageHelper.startPage(1, 20);
        List<User> list = userMapper.selectByExample(example);
        assertEquals(1, list.get(0).getId());
        assertEquals(5, list.size());
        assertEquals(5, ((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) UserExample(com.github.pagehelper.model.UserExample) 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