Search in sources :

Example 16 with Country

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

the class TestISelect method testGroupBy2.

@Test
public void testGroupBy2() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    final CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        Page<Country> page = PageHelper.startPage(1, 10).doSelectPage(new ISelect() {

            @Override
            public void doSelect() {
                countryMapper.selectGroupBy();
            }
        });
        //下面是该方法的lambda用法
        //Page<Country> page = PageHelper.startPage(1, 10).setOrderBy("id desc").doSelectPage(()-> countryMapper.selectGroupBy());
        //1,'Angola','AO'
        assertEquals(1, page.get(0).getId());
        assertEquals(10, page.size());
        assertEquals(183, page.getTotal());
        PageInfo<Country> pageInfo = page.toPageInfo();
        System.out.println(pageInfo);
        pageInfo = PageHelper.startPage(1, 10).doSelectPageInfo(new ISelect() {

            @Override
            public void doSelect() {
                countryMapper.selectGroupBy();
            }
        });
        //lambda
        //pageInfo = PageHelper.startPage(1, 10).setOrderBy("id desc").doSelectPageInfo(() -> countryMapper.selectGroupBy());
        System.out.println(pageInfo);
        final Country country = new Country();
        country.setCountryname("c");
        long total = PageHelper.count(new ISelect() {

            @Override
            public void doSelect() {
                countryMapper.selectLike(country);
            }
        });
        //lambda
        //long total = PageHelper.count(()->countryMapper.selectLike(country));
        System.out.println(total);
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) CountryMapper(com.github.pagehelper.mapper.CountryMapper) Country(com.github.pagehelper.model.Country) ISelect(com.github.pagehelper.ISelect) Test(org.junit.Test)

Example 17 with Country

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

the class TestDynamicChoose 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.selectChoose(1, 2);
        assertEquals(2, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(182, ((Page<?>) list).getTotal());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        list = countryMapper.selectChoose(1, 2);
        assertEquals(2, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(182, ((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 18 with Country

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

the class TestDynamicIf method testMapper.

/**
     * 单个POJO参数情况特殊
     */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testMapper() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        Map map = new HashMap();
        Country country = new Country();
        country.setId(1);
        map.put("country", country);
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        List<Country> list = countryMapper.selectIf3(country);
        assertEquals(2, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(182, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) HashMap(java.util.HashMap) CountryMapper(com.github.pagehelper.mapper.CountryMapper) Country(com.github.pagehelper.model.Country) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 19 with Country

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

the class TestDynamicIf2 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.selectIf2(1, 2);
        assertEquals(3, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(181, ((Page<?>) list).getTotal());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        list = countryMapper.selectIf2(1, null);
        assertEquals(2, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(182, ((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 20 with Country

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

the class TestDynamicIfOrder 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.selectIf2ListAndOrder(Arrays.asList(1, 2), Arrays.asList(3, 4), null);
        assertEquals(5, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(179, ((Page<?>) list).getTotal());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        list = countryMapper.selectIf2ListAndOrder(Arrays.asList(1, 2), null, "id");
        assertEquals(3, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(181, ((Page<?>) list).getTotal());
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        list = countryMapper.selectIf2ListAndOrder(new ArrayList<Integer>(0), null, "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) ArrayList(java.util.ArrayList) 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