Search in sources :

Example 1 with UserQueryModel

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

the class ArgumentsObjTest method testArgumentsObj.

/**
 * 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
 */
@Test
public void testArgumentsObj() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        UserQueryModel queryModel = new UserQueryModel();
        queryModel.setPageNum(1);
        queryModel.setPageSize(10);
        queryModel.setOrderBy("id desc");
        List<User> list = userMapper.selectByQueryModel(queryModel);
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        queryModel.setPageNum(2);
        queryModel.setOrderBy(null);
        list = userMapper.selectByQueryModel(queryModel);
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        queryModel.setPageNum(3);
        queryModel.setPageSize(20);
        list = userMapper.selectByQueryModel(queryModel);
        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) UserQueryModel(com.github.pagehelper.model.UserQueryModel) Test(org.junit.Test)

Aggregations

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