3.service层:
public PageInfo getAllSold(Integer pageNum, Integer pageSize) { PageHelper.startPage(pageNum,pageSize);//在查询语句前加入该句,查询会自动物理分页 List soldList = productMapper.selectAllSold(Dict.productSold); PageInfo pageInfo = new PageInfo(soldList); return pageInfo; }
4.controller:
@RequestMapping(value = "/") public String getIndexPage(Model model, @RequestParam(value = "pageNum", required = false) Integer pageNum, @RequestParam(value = "pageSize", required = false) Integer pageSize, @RequestParam(value = "userId", required = false) Integer userId){ if (pageNum == null || pageNum.equals("")) { pageNum = 1; } if (pageSize == null || pageSize.equals("")) { pageSize = Dict.pageSize;//每页显示的数目 } //利用url传递参数,进行分页 if (httpServletRequest.getQueryString() == null) { model.addAttribute("urlForFenYe", httpServletRequest.getRequestURI() + "?"); } else { String url = httpServletRequest.getRequestURI() + "?" + httpServletRequest.getQueryString(); String[] urls = url.split("pageNum"); model.addAttribute("urlForFenYe", urls[0]); } PageInfo pageInfo = productServiceImp.getAllProductInformByUserId(pageNum,pageSize,userId); model.addAttribute("infoCount", pageInfo.getTotal()); model.addAttribute("pageNum", pageNum); model.addAttribute("pageSize",Dict.pageSize); model.addAttribute("ProductSold",Dict.productSold); model.addAttribute("allProductList",pageInfo); return "index"; }
5.前端
© 著作权归作者所有
作者:ty淡然
原文:https://my.oschina.net/u/3424784/blog/3000946