service 接口代码
PageInfo findByPage2(Integer currPage, Integer pageSize);
service实现类代码
public PageInfo findByPage2(Integer currPage, Integer pageSize) {
PageHelper.startPage(currPage,pageSize);
List productList = productDao.findAll();
PageInfo pageInfo = new PageInfo(productList,3);
return pageInfo;
}
controller控制层代码
@RequestMapping("/findAll2")
public ModelAndView findAll2(@RequestParam(value = "currPage", defaultValue = "1") Integer currPage,
@RequestParam(value = "pageSize", required = false, defaultValue = "3") Integer pageSize) {
// 准备分页数据
PageInfo pageInfo = productService.findByPage2(currPage, pageSize);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("pageInfo", pageInfo);
// 指定页面
modelAndView.setViewName("product-listhelper");
return modelAndView;
}
内容来源于网络如有侵权请私信删除