Search in sources :

Example 1 with ISelect

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

Aggregations

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