java分页查询代码
service 接口代码
PageInfo<Product> findByPage2(Integer currPage, Integer pageSize);
service实现类代码
public PageInfo<Product> findByPage2(Integer currPage, Integer pageSize) {
PageHelper.startPage(currPage,pageSize);
List<Product> productList = productDao.findAll();
PageInfo<Product> pageInfo = new PageInfo<Product>(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<Product> pageInfo = productService.findByPage2(currPage, pageSize);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("pageInfo", pageInfo);
// 指定页面
modelAndView.setViewName("product-listhelper");
return modelAndView;
}
相关文章