Search in sources :

Example 56 with Country

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

the class TestDynamicIfTwoList method testMapperWithStartPage.

/**
     * 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
     */
@Test
public void testMapperWithStartPage() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        List<Country> list = countryMapper.selectIf2List(Arrays.asList(1, 2), Arrays.asList(3, 4));
        assertEquals(5, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(179, ((Page<?>) list).getTotal());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        list = countryMapper.selectIf2List(Arrays.asList(1, 2), null);
        assertEquals(3, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(181, ((Page<?>) list).getTotal());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        list = countryMapper.selectIf2List(new ArrayList<Integer>(0), null);
        assertEquals(1, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) CountryMapper(com.github.pagehelper.mapper.CountryMapper) ArrayList(java.util.ArrayList) Country(com.github.pagehelper.model.Country) Test(org.junit.Test)

Example 57 with Country

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

the class TestExample method testNull.

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

Example 58 with Country

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

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

Example 60 with Country

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

the class TestParameterArray method testMapperWithStartPage.

/**
     * 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
     */
@Test
public void testMapperWithStartPage() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        List<Country> list = countryMapper.selectAllOrderByArray(new Integer[] { 1, 2 });
        assertEquals(3, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(181, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) CountryMapper(com.github.pagehelper.mapper.CountryMapper) Country(com.github.pagehelper.model.Country) Test(org.junit.Test)

Aggregations

Country (com.github.pagehelper.model.Country)71 SqlSession (org.apache.ibatis.session.SqlSession)71 Test (org.junit.Test)71 CountryMapper (com.github.pagehelper.mapper.CountryMapper)57 RowBounds (org.apache.ibatis.session.RowBounds)14 HashMap (java.util.HashMap)12 PageInfo (com.github.pagehelper.PageInfo)11 ArrayList (java.util.ArrayList)5 PageRowBounds (com.github.pagehelper.PageRowBounds)4 CountryExample (com.github.pagehelper.model.CountryExample)2 ISelect (com.github.pagehelper.ISelect)1 CountryQueryModel (com.github.pagehelper.model.CountryQueryModel)1 Map (java.util.Map)1