Search in sources :

Example 1 with UserExample

use of com.github.pagehelper.model.UserExample 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 2 with UserExample

use of com.github.pagehelper.model.UserExample 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

UserMapper (com.github.pagehelper.mapper.UserMapper)2 User (com.github.pagehelper.model.User)2 UserExample (com.github.pagehelper.model.UserExample)2 SqlSession (org.apache.ibatis.session.SqlSession)2 Test (org.junit.Test)2