请结合springboot学习教程项目github地址 https://github.com/heng1234/spring-boot_one来理解
pom需要加入pagehelper的jar
service
/**
* 分页查询
*/
@Override
@Transactional(propagation=Propagation.SUPPORTS)
public List<TUser> findPageListTuser(int page, int pageSize) {
PageHelper.startPage(page, pageSize);
Example example = new Example(TUser.class);
Example.Criteria criteria = example.createCriteria();
return tuserMapper.selectByExample(example);
}
controller
/**
* 分页查询
*/
@RequestMapping("findPageListTuser")
@ResponseBody
public List<TUser> findPageListTuser(Integer page) {
if(page == null) {
page = 1; //页面
}
Integer pageSize = 6;//每页显示数量
List<TUser> list = tuserService.findPageListTuser(page, pageSize);
System.out.println(list.size());
return list;
}