Search in sources :

Example 51 with CountryMapper

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

the class TestUnion method testUnion.

/**
     * union的count查询sql特殊
     */
@Test
public void testUnion() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        List<Country> list = countryMapper.selectUnion();
        assertEquals(1, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(13, ((Page<?>) list).getTotal());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(2, 10);
        list = countryMapper.selectUnion();
        assertEquals(181, list.get(0).getId());
        assertEquals(3, list.size());
        assertEquals(13, ((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 52 with CountryMapper

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

the class TestWith method testUnion.

/**
     * with的count查询sql特殊 - 只测试oracle,别的可能不支持
     */
@Test
public void testUnion() throws Exception {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    //只测试oracle
    if (!TestUtil.getXmlPath().equalsIgnoreCase("oracle")) {
        return;
    }
    try {
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        List<Country> list = countryMapper.selectWith();
        assertEquals(151, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(33, ((Page<?>) list).getTotal());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(2, 10);
        list = countryMapper.selectWith();
        assertEquals(161, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(33, ((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 53 with CountryMapper

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

the class TestLike 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);
        Country country = new Country();
        country.setCountryname("c");
        List<Country> list = countryMapper.selectLike(country);
        assertEquals(30, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(39, ((Page<?>) list).getTotal());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(4, 10);
        list = countryMapper.selectLike(country);
        assertEquals(130, list.get(0).getId());
        assertEquals(9, list.size());
        assertEquals(39, ((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 54 with CountryMapper

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

the class TestAnnotations 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.selectByOrder2("id");
        assertEquals(1, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        list = countryMapper.selectByOrder("countryname");
        assertEquals(2, 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 55 with CountryMapper

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

the class SecondCacheTest method test1.

@Test
public void test1() {
    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());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        list = countryMapper.selectGreterThanId(10);
        assertEquals(10, list.size());
    } finally {
        sqlSession.close();
    }
    sqlSession = MybatisHelper.getSqlSession();
    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)

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