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

The following examples show how to use com.github.pagehelper.PageInfo#getPageNum() . 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: PageUtil.java    From agile-service-old with Apache License 2.0 5 votes vote down vote up
public static PageInfo buildPageInfoWithPageInfoList(PageInfo pageInfo, List list) {
    Page page = new Page<>(pageInfo.getPageNum(), pageInfo.getPageSize());
    page.setTotal(pageInfo.getTotal());
    page.addAll(list);

    return page.toPageInfo();
}
 
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: PageUtils.java    From product-recommendation-system with MIT License 4 votes vote down vote up
/**
 * 根据前台组件生成的分页条
 * @param pageInfo 分页的信息
 * @param queryMethod 前台的分页查询方法
 * @return
 */
public static String pageStr (PageInfo<?> pageInfo, String queryMethod) {
	StringBuffer buffer = new StringBuffer("<ul class=\"pagination\">");
	// 判断当前页是不是首页
	if (pageInfo.isIsFirstPage() || pageInfo.getPrePage() ==  0) {
		buffer.append("<li class=\"disabled\"><a href=\"javascript:void(0);\" aria-label=\"Previous\">«</a></li>");
	} else {
		buffer.append("<li><a href=\"javascript:").append(queryMethod).append("(");
		buffer.append(pageInfo.getPrePage()).append(",");
		buffer.append(pageInfo.getPageSize());
		buffer.append(")\" aria-label=\"Previous\">«</a></li>");
	}
	
	// 拼接中间的数字部分
	for (int i = 0; i < pageInfo.getNavigatepageNums().length; i++) {
		int pageNum = pageInfo.getNavigatepageNums()[i];
		// pageNum为当前的页码
		if (pageInfo.getPageNum() == pageNum) {
			buffer.append("<li class=\"active\"><a href=\"javascript:\">");
			buffer.append(pageNum).append("</a></li>");
		} else {
			buffer.append("<li><a href=\"javascript:");
			buffer.append(queryMethod).append("(");
			buffer.append(pageNum).append(",");
			buffer.append(pageInfo.getPageSize()).append(");\">");
			buffer.append(pageNum).append("</a></li>");
		}
	}
	
	// 判断是不是尾页
	if (pageInfo.isIsLastPage() || pageInfo.getNextPage() == 0) {
		buffer.append("<li class=\"disabled\"><a href=\"javascript:void(0);\" aria-label=\"Next\">»</a></li>");
	} else {
		buffer.append("<li><a href=\"javascript:").append(queryMethod).append("(");
		buffer.append(pageInfo.getNextPage()).append(",");
		buffer.append(pageInfo.getPageSize()).append(");");
		buffer.append("\" aria-label=\"Next\">»</a></li>");
	}
	buffer.append("</ul>");
	
	return buffer.toString();
}
 
Example 7
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 8
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 9
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 10
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;
}