Search in sources :

Example 6 with CountryMapper

use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.

the class SecondCacheTest method test2.

@Test
public void test2() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        List<Country> list = countryMapper.selectGreterThanId(10);
        assertEquals(10, list.size());
    } 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 7 with CountryMapper

use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.

the class TestSelectItems method testSelectColumns.

/**
     * 查询自定义列时 - 实际上这个测试由于使用${},并没有起到真正的目的
     */
@Test
public void testSelectColumns() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        List<Country> list = countryMapper.selectColumns();
        //1,'Angola','AO'
        assertEquals(1, list.get(0).getId());
        assertEquals("Angola", list.get(0).getCountryname());
        assertEquals("AO", list.get(0).getCountrycode());
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        list = countryMapper.selectColumns("id", "countryname");
        //1,'Angola','AO'
        assertEquals(1, list.get(0).getId());
        assertEquals("Angola", list.get(0).getCountryname());
        assertNull(list.get(0).getCountrycode());
        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) Country(com.github.pagehelper.model.Country) Test(org.junit.Test)

Example 8 with CountryMapper

use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.

the class TestSelectItems method testSelectColumn2.

/**
     * 使用#{}在查询列中进行计算,count查询时需要特殊对待
     */
@Test
public void testSelectColumn2() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        List<Country> list = countryMapper.selectMULId(1);
        //1,'Angola','AO'
        assertEquals(1, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        list = countryMapper.selectMULId(5);
        //1,'Angola','AO'
        assertEquals(5, 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) Country(com.github.pagehelper.model.Country) Test(org.junit.Test)

Example 9 with CountryMapper

use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.

the class OffsetTest method testOffset.

@Test
public void testOffset() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        PageHelper.startPage(1, 6);
        List<Country> list = countryMapper.selectAll();
        assertEquals(6, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        PageHelper.offsetPage(6, 20);
        list = countryMapper.selectAll();
        PageInfo<Country> pageInfo = new PageInfo<Country>(list);
        System.out.println(pageInfo.toString());
        assertEquals(2, ((Page<?>) list).getPageNum());
        assertEquals(20, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}
Also used : PageInfo(com.github.pagehelper.PageInfo) SqlSession(org.apache.ibatis.session.SqlSession) CountryMapper(com.github.pagehelper.mapper.CountryMapper) Country(com.github.pagehelper.model.Country) Test(org.junit.Test)

Example 10 with CountryMapper

use of com.github.pagehelper.mapper.CountryMapper in project Mybatis-PageHelper by pagehelper.

the class OffsetTest method testPageNum.

@Test
public void testPageNum() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        PageHelper.offsetPage(5, 5);
        List<Country> list = countryMapper.selectAll();
        assertEquals(2, ((Page<?>) list).getPageNum());
        assertEquals(5, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        PageHelper.offsetPage(15, 5);
        list = countryMapper.selectAll();
        assertEquals(4, ((Page<?>) list).getPageNum());
        assertEquals(5, 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)

Aggregations

CountryMapper (com.github.pagehelper.mapper.CountryMapper)57 Country (com.github.pagehelper.model.Country)57 SqlSession (org.apache.ibatis.session.SqlSession)57 Test (org.junit.Test)57 PageInfo (com.github.pagehelper.PageInfo)11 RowBounds (org.apache.ibatis.session.RowBounds)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 PageRowBounds (com.github.pagehelper.PageRowBounds)2 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