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