Search in sources :

Example 1 with CountryQueryModel

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

the class ArgumentsObjTest method testArgumentsObj.

/**
     * 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
     */
@Test
public void testArgumentsObj() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        CountryQueryModel queryModel = new CountryQueryModel();
        queryModel.setPageNum(1);
        queryModel.setPageSize(10);
        queryModel.setOrderBy("id desc");
        List<Country> list = countryMapper.selectByQueryModel(queryModel);
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        queryModel.setPageNum(2);
        queryModel.setOrderBy(null);
        list = countryMapper.selectByQueryModel(queryModel);
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        queryModel.setPageNum(3);
        queryModel.setPageSize(20);
        list = countryMapper.selectByQueryModel(queryModel);
        assertEquals(20, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}
Also used : CountryQueryModel(com.github.pagehelper.model.CountryQueryModel) SqlSession(org.apache.ibatis.session.SqlSession) CountryMapper(com.github.pagehelper.mapper.CountryMapper) Country(com.github.pagehelper.model.Country) Test(org.junit.Test)

Aggregations

CountryMapper (com.github.pagehelper.mapper.CountryMapper)1 Country (com.github.pagehelper.model.Country)1 CountryQueryModel (com.github.pagehelper.model.CountryQueryModel)1 SqlSession (org.apache.ibatis.session.SqlSession)1 Test (org.junit.Test)1