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();
}
}
Aggregations