Search in sources :

Example 1 with CountryExample

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

the class TestExample method testInList.

@Test
public void testInList() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        CountryExample example = new CountryExample();
        example.createCriteria().andIdIn(Arrays.asList(1, 2, 3, 4, 5));
        PageHelper.startPage(1, 20);
        List<Country> list = countryMapper.selectByExample(example);
        assertEquals(1, list.get(0).getId());
        assertEquals(5, list.size());
        assertEquals(5, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) CountryMapper(com.github.pagehelper.mapper.CountryMapper) CountryExample(com.github.pagehelper.model.CountryExample) Country(com.github.pagehelper.model.Country) Test(org.junit.Test)

Example 2 with CountryExample

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

the class TestExample method testGreaterThan.

@Test
public void testGreaterThan() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        CountryExample example = new CountryExample();
        example.createCriteria().andIdGreaterThan(100);
        PageHelper.startPage(1, 20);
        List<Country> list = countryMapper.selectByExample(example);
        assertEquals(101, list.get(0).getId());
        assertEquals(20, list.size());
        assertEquals(83, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) CountryMapper(com.github.pagehelper.mapper.CountryMapper) CountryExample(com.github.pagehelper.model.CountryExample) Country(com.github.pagehelper.model.Country) Test(org.junit.Test)

Aggregations

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