Java Code Examples for com.github.pagehelper.PageInfo#getPages()

The following examples show how to use com.github.pagehelper.PageInfo#getPages() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResultData.java    From java-tutorial with MIT License 5 votes vote down vote up
public ResultData(PageInfo info) {
    this.totalNum = (int) info.getTotal();
    this.pageNum = info.getPageNum();
    this.totalPage = info.getPages();
    this.items = info.getList();
    this.isMore = info.getPageNum() < info.getPages();
}
 
Example 2
Source File: TripController.java    From newblog with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/ajaxpic")
public void ajaxpic(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String page = request.getParameter("page");
    Integer pagenum;
    if (StringUtils.isEmpty(page)) {
        pagenum = 1;
    } else {
        pagenum = Integer.parseInt(page);
    }
    PageHelper.startPage(pagenum, 15);
    List<Image> lists = imageService.getAllImage();
    PageInfo<Image> images = new PageInfo<>(lists);
    Gson gson = new Gson();
    JsonArray jsonArray = new JsonArray();
    for (Image image : images.getList()) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("photo_id", image.getImageid());
        jsonObject.addProperty("unm", image.getImagename());
        jsonObject.addProperty("uid", image.getImageid());
        jsonObject.addProperty("ava", image.getImagepath());
        jsonObject.addProperty("isrc", image.getImagepath());
        jsonObject.addProperty("id", image.getImageid());
        jsonObject.addProperty("msg", image.getContent());
        jsonObject.addProperty("iht", image.getIht());
        jsonArray.add(jsonObject);
    }
    long totalcount = images.getPages();
    String temp = ",\"totalcount\":" + String.valueOf(totalcount) + ",\"has_next\":" +
            String.valueOf(pagenum < totalcount) + "";
    String str = gson.toJson(jsonArray);
    String json = "{\"data\":{\"blogs\":" + str + ",\"hasrp\":true,\"pgsource\":" +
            "\"_\",\"nopth\":false" + temp + "},\"success\":true}";
    response.getWriter().write(json);
}
 
Example 3
Source File: IndexController.java    From newblog with Apache License 2.0 5 votes vote down vote up
/**
 * 首页
 *
 * @param request
 * @return
 * @throws Exception
 */
@RequestMapping("/")
public ModelAndView first(HttpServletRequest request) throws Exception {
    String page = request.getParameter("pagenum");
    Integer pagenum;
    if (StringUtils.isEmpty(page)) {
        pagenum = 1;
    } else {
        pagenum = Integer.parseInt(page);
    }
    PageHelper.startPage(pagenum, 15);
    ModelAndView mav = new ModelAndView();
    List<Blog> lists = blogService.getAllBlog();
    List<Blog> banners = blogService.getBanner();
    PageInfo<Blog> blogs = new PageInfo<>(lists);
    Integer startpage, endpage;
    if (blogs.getPages() < 6) {
        startpage = 1;
        endpage = blogs.getPages();
    } else {
        if (pagenum > 3) {
            startpage = blogs.getPageNum() - 3;
            endpage = blogs.getPageNum() + 3 > blogs.getPages() ? blogs.getPages() : blogs.getPageNum() + 3;
        } else {
            startpage = 1;
            endpage = blogs.getPageNum() + 4;
        }
    }
    List<Blog> hotblogs = blogService.getByHits();
    mav.addObject("startpage", startpage);
    mav.addObject("endpage", endpage);
    mav.addObject("hotblogs", hotblogs);
    mav.addObject("blogs", blogs.getList());
    mav.addObject("totalpages", blogs.getPages());
    mav.addObject("pageNum", blogs.getPageNum());
    mav.addObject("banners", banners);
    mav.setViewName("index");
    return mav;
}
 
Example 4
Source File: IndexController.java    From newblog with Apache License 2.0 5 votes vote down vote up
/**
 * 首页
 *
 * @param request
 * @return
 * @throws Exception
 */
@RequestMapping("/index")
public ModelAndView index(HttpServletRequest request) throws Exception {
    String page = request.getParameter("pagenum");
    Integer pagenum;
    if (StringUtils.isEmpty(page)) {
        pagenum = 1;
    } else {
        pagenum = Integer.parseInt(page);
    }
    PageHelper.startPage(pagenum, 15);
    ModelAndView mav = new ModelAndView();
    List<Blog> lists = blogService.getAllBlog();
    List<Blog> banners = blogService.getBanner();
    PageInfo<Blog> blogs = new PageInfo<>(lists);
    Integer startpage, endpage;
    if (blogs.getPages() < 6) {
        startpage = 1;
        endpage = blogs.getPages();
    } else {
        if (pagenum > 3) {
            startpage = blogs.getPageNum() - 3;
            endpage = blogs.getPageNum() + 3 > blogs.getPages() ? blogs.getPages() : blogs.getPageNum() + 3;
        } else {
            startpage = 1;
            endpage = blogs.getPageNum() + 4;
        }
    }
    List<Blog> hotblogs = blogService.getByHits();
    mav.addObject("startpage", startpage);
    mav.addObject("endpage", endpage);
    mav.addObject("hotblogs", hotblogs);
    mav.addObject("blogs", blogs.getList());
    mav.addObject("totalpages", blogs.getPages());
    mav.addObject("pageNum", blogs.getPageNum());
    mav.addObject("banners", banners);
    mav.setViewName("index");
    return mav;
}
 
Example 5
Source File: BaseController.java    From maintain with MIT License 5 votes vote down vote up
private List<Integer> buildPageList(PageInfo pageInfo) {
	List<Integer> pageList = new ArrayList<Integer>();
	
	if (3 >= pageInfo.getPageNum()) {
		for (int i = 1; i <= pageInfo.getPages() && i <= 5; i++) {
			pageList.add(i);
		}
	} else {
		if (2 < pageInfo.getPages() - pageInfo.getPageNum()) {
			pageList.add(pageInfo.getPageNum() - 2);
			pageList.add(pageInfo.getPageNum() - 1);
			pageList.add(pageInfo.getPageNum());
			pageList.add(pageInfo.getPageNum() + 1);
			pageList.add(pageInfo.getPageNum() + 2);
		} else {
			if (5 <= pageInfo.getPages()) {
				pageList.add(pageInfo.getPages() - 4);
				pageList.add(pageInfo.getPages() - 3);
				pageList.add(pageInfo.getPages() - 2);
				pageList.add(pageInfo.getPages() - 1);
				pageList.add(pageInfo.getPages());
			} else {
				pageList.add(1);
				pageList.add(2);
				pageList.add(3);
				pageList.add(4);
			}
		}
	}
	
	return pageList;
}
 
Example 6
Source File: BlogController.java    From newblog with Apache License 2.0 4 votes vote down vote up
@RequestMapping("/tech")
public ModelAndView to_show_article(HttpServletRequest request) {       //博客主页
    ModelAndView modelAndView = new ModelAndView();
    String page = request.getParameter("pagenum");
    String categoryid = request.getParameter("categoryid");
    String t_id = request.getParameter("tid");
    Integer pagenum;
    if (StringUtils.isEmpty(page)) {
        pagenum = 1;
    } else {
        pagenum = Integer.parseInt(page);
    }
    PageHelper.startPage(pagenum, 15);
    List<Blog> lists;
    if (StringUtils.isNotEmpty(categoryid)) {
        lists = blogService.getByCategoryId(Integer.parseInt(categoryid));
        Category category = categoryService.selectByPrimaryKey(Integer.parseInt(categoryid));
        modelAndView.addObject("category", category);
    } else if (StringUtils.isNotEmpty(t_id)) {
        lists = blogService.getBlogByTagId(Integer.parseInt(t_id));
        Tag tag = blogService.getTagByTid(Integer.parseInt(t_id));
        modelAndView.addObject("tag", tag);
    } else {
        lists = blogService.getAllTechBlog();
    }
    for (Blog list : lists) {
        try {
            int category_id = list.getCategoryid();//bug fix 2017-11-13
            list.setCategory(categoryService.selectByPrimaryKey(category_id));
        } catch (Exception e) {
            logger.error("分类设置" + e);
        }
    }
    PageInfo<Blog> blogs = new PageInfo<>(lists);
    Integer startpage, endpage;
    if (blogs.getPages() < 6) {
        startpage = 1;
        endpage = blogs.getPages();
    } else {
        if (pagenum > 3) {
            startpage = blogs.getPageNum() - 3;
            endpage = blogs.getPageNum() + 3 > blogs.getPages() ? blogs.getPages() : pagenum + 3;
        } else {
            startpage = 1;
            endpage = blogs.getPageNum() + 4 > blogs.getPages() ? blogs.getPages() : pagenum + 4;
        }
    }
    modelAndView.addObject("startpage", startpage);
    modelAndView.addObject("endpage", endpage);
    modelAndView.addObject("blogs", blogs.getList());
    modelAndView.addObject("totalpages", blogs.getPages());
    modelAndView.addObject("pageNum", blogs.getPageNum());
    modelAndView.setViewName("tech");
    return modelAndView;
}
 
Example 7
Source File: BlogController.java    From newblog with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/search")
public ModelAndView search(
        @RequestParam(value = "keyword", required = false) String keyword,
        @RequestParam(value = "pagenum", required = false) Integer pagenum) {
    ModelAndView modelAndView = new ModelAndView();
    try {
        if (pagenum == null) {
            pagenum = 1;
        }
        List<Blog> lists = blogService.getLuceneBlog(pagenum, keyword, 10);
        PageHelper.startPage(pagenum, 10);
        PageInfo<Blog> blogs = new PageInfo<>(lists);
        blogs.setPageSize(10);
        blogs.setSize(10);
        blogs.setPages(lists.size() / 10 == 0 ? lists.size() / 10 : lists.size() / 10 + 1);
        Integer startpage, endpage;
        if (blogs.getPages() < 6) {
            startpage = 1;
            endpage = blogs.getPages();
        } else {
            if (pagenum > 3) {
                startpage = blogs.getPageNum() - 3;
                endpage = blogs.getPageNum() + 3;
            } else {
                startpage = 1;
                endpage = blogs.getPageNum() + 4;
            }
        }
        modelAndView.addObject("startpage", startpage);
        modelAndView.addObject("endpage", endpage);
        modelAndView.addObject("blogs", blogs.getList());
        modelAndView.addObject("totalpages", blogs.getPages());
        modelAndView.addObject("pageNum", pagenum);
        modelAndView.addObject("keyword", keyword);
        modelAndView.setViewName("searchresult");
    } catch (Exception e) {
        e.printStackTrace();
        logger.error("search" + e);
    }
    return modelAndView;
}
 
Example 8
Source File: CategoryController.java    From newblog with Apache License 2.0 4 votes vote down vote up
@RequestMapping("/getbycategoryid")
public ModelAndView getbycategoryid(HttpServletRequest request, HttpServletResponse response) {
    ModelAndView modelAndView = new ModelAndView();
    Integer cid = Integer.parseInt(request.getParameter("cid"));
    String page = request.getParameter("pagenum");
    String categoryid = request.getParameter("categoryid");
    String t_id = request.getParameter("tid");
    if (cid == 0) {
        try {
            response.sendRedirect("life.html");
        } catch (IOException e) {
            logger.error("getbycategoryid", e);
        }
    }
    Integer pagenum;
    if (StringUtils.isEmpty(page)) {
        pagenum = 1;
    } else {
        pagenum = Integer.parseInt(page);
    }
    PageHelper.startPage(pagenum, 15);
    List<Blog> lists = blogService.getByCategoryId(cid);
    PageInfo<Blog> blogs = new PageInfo<>(lists);
    Integer startpage, endpage;
    if (blogs.getPages() < 6) {
        startpage = 1;
        endpage = blogs.getPages();
    } else {
        if (pagenum > 3) {
            startpage = blogs.getPageNum() - 3;
            endpage = blogs.getPageNum() + 3 > blogs.getPages() ? blogs.getPages() : pagenum + 3;
        } else {
            startpage = 1;
            endpage = blogs.getPageNum() + 4 > blogs.getPages() ? blogs.getPages() : pagenum + 4;
        }
    }
    modelAndView.addObject("startpage", startpage);
    modelAndView.addObject("endpage", endpage);
    modelAndView.addObject("blogs", blogs.getList());
    modelAndView.addObject("totalpages", blogs.getPages());
    modelAndView.addObject("pageNum", blogs.getPageNum());
    modelAndView.setViewName("tech");
    return modelAndView;
}
 
Example 9
Source File: LifeController.java    From newblog with Apache License 2.0 4 votes vote down vote up
@RequestMapping("/life")
public ModelAndView toshowarticle(HttpServletRequest request) {       //生活笔记
    String page = request.getParameter("pagenum");
    String categoryid = request.getParameter("categoryid");
    String t_id = request.getParameter("tid");
    Integer pagenum;
    if (StringUtils.isEmpty(page)) {
        pagenum = 1;
    } else {
        pagenum = Integer.parseInt(page);
    }
    PageHelper.startPage(pagenum, 15);
    List<Blog> lists;
    if (StringUtils.isEmpty(categoryid)) {
        lists = blogService.getLife();
    } else if (!StringUtils.isEmpty(t_id)) {
        lists = blogService.getBlogByTagId(Integer.parseInt(t_id));
    } else {
        lists = blogService.getByCategoryId(Integer.parseInt(categoryid));
    }
    ModelAndView modelAndView = new ModelAndView();
    for (Blog list : lists) {
        try {
            int category_id = lists.get(0).getCategoryid();
            list.setCategory(categoryService.selectByPrimaryKey(category_id));
        } catch (Exception e) {
            logger.error("datetimeparse error" + e);
        }
    }
    if (categoryid != null && !categoryid.equals("")) {
        Category category = categoryService.selectByPrimaryKey(Integer.parseInt(categoryid));
        modelAndView.addObject("category", category);
    } else {
        if (t_id != null) {
            Tag tag = blogService.getTagByTid(Integer.parseInt(t_id));
            modelAndView.addObject("tag", tag);
        }
    }
    PageInfo<Blog> blogs = new PageInfo<>(lists);
    Integer startpage, endpage;
    if (blogs.getPages() < 6) {
        startpage = 1;
        endpage = blogs.getPages();
    } else {
        if (pagenum > 3) {
            startpage = blogs.getPageNum() - 3;
            endpage = blogs.getPageNum() + 3 > blogs.getPages() ? blogs.getPages() : pagenum + 3;
        } else {
            startpage = 1;
            endpage = blogs.getPageNum() + 4 > blogs.getPages() ? blogs.getPages() : pagenum + 4;
        }
    }
    modelAndView.addObject("startpage", startpage);
    modelAndView.addObject("endpage", endpage);
    modelAndView.addObject("blogs", blogs.getList());
    modelAndView.addObject("totalpages", blogs.getPages());
    modelAndView.addObject("pageNum", blogs.getPageNum());
    modelAndView.setViewName("life");
    return modelAndView;
}