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

The following examples show how to use com.github.pagehelper.PageInfo#setPages() . 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: PageInfoHelper.java    From uexam with GNU Affero General Public License v3.0 6 votes vote down vote up
public static <T, J> PageInfo<J> copyMap(PageInfo<T> source, Function<? super T, ? extends J> mapper) {
    PageInfo<J> newPage = new PageInfo<>();
    newPage.setPageNum(source.getPageNum());
    newPage.setPageSize(source.getPageSize());
    newPage.setSize(source.getSize());
    newPage.setStartRow(source.getStartRow());
    newPage.setEndRow(source.getEndRow());
    newPage.setTotal(source.getTotal());
    newPage.setPages(source.getPages());
    newPage.setList(source.getList().stream().map(mapper).collect(Collectors.toList()));
    newPage.setPrePage(source.getPrePage());
    newPage.setNextPage(source.getNextPage());
    newPage.setIsFirstPage(source.isIsFirstPage());
    newPage.setIsLastPage(source.isIsLastPage());
    newPage.setHasPreviousPage(source.isHasPreviousPage());
    newPage.setHasNextPage(source.isHasNextPage());
    newPage.setNavigatePages(source.getNavigatePages());
    newPage.setNavigatepageNums(source.getNavigatepageNums());
    newPage.setNavigateFirstPage(source.getNavigateFirstPage());
    newPage.setNavigateLastPage(source.getNavigateLastPage());
    return newPage;
}
 
Example 2
Source File: PageUtil.java    From spring-microservice-exam with MIT License 6 votes vote down vote up
/**
 * 复制属性
 *
 * @param source source
 * @param target target
 * @author tangyi
 * @date 2019/07/03 22:26:18
 */
public static void copyProperties(PageInfo<?> source, PageInfo<?> target) {
    target.setPageNum(source.getPageNum());
    target.setPageSize(source.getPageSize());
    target.setSize(source.getSize());
    target.setStartRow(source.getStartRow());
    target.setEndRow(source.getEndRow());
    target.setPages(source.getPages());
    target.setPrePage(source.getPrePage());
    target.setNextPage(source.getNextPage());
    target.setIsFirstPage(source.isIsFirstPage());
    target.setIsLastPage(source.isIsLastPage());
    target.setHasPreviousPage(source.isHasPreviousPage());
    target.setHasNextPage(source.isHasNextPage());
    target.setNavigatePages(source.getNavigatePages());
    target.setNavigatepageNums(source.getNavigatepageNums());
    target.setNavigateFirstPage(source.getNavigateFirstPage());
    target.setNavigateLastPage(source.getNavigateLastPage());
    target.setTotal(source.getTotal());
}
 
Example 3
Source File: PageInfoHelper.java    From uexam-mysql with GNU Affero General Public License v3.0 6 votes vote down vote up
public static <T, J> PageInfo<J> copyMap(PageInfo<T> source, Function<? super T, ? extends J> mapper) {
    PageInfo<J> newPage = new PageInfo<>();
    newPage.setPageNum(source.getPageNum());
    newPage.setPageSize(source.getPageSize());
    newPage.setSize(source.getSize());
    newPage.setStartRow(source.getStartRow());
    newPage.setEndRow(source.getEndRow());
    newPage.setTotal(source.getTotal());
    newPage.setPages(source.getPages());
    newPage.setList(source.getList().stream().map(mapper).collect(Collectors.toList()));
    newPage.setPrePage(source.getPrePage());
    newPage.setNextPage(source.getNextPage());
    newPage.setIsFirstPage(source.isIsFirstPage());
    newPage.setIsLastPage(source.isIsLastPage());
    newPage.setHasPreviousPage(source.isHasPreviousPage());
    newPage.setHasNextPage(source.isHasNextPage());
    newPage.setNavigatePages(source.getNavigatePages());
    newPage.setNavigatepageNums(source.getNavigatepageNums());
    newPage.setNavigateFirstPage(source.getNavigateFirstPage());
    newPage.setNavigateLastPage(source.getNavigateLastPage());
    return newPage;
}
 
Example 4
Source File: PageInfoHelper.java    From dynamic-data-source-demo with Apache License 2.0 6 votes vote down vote up
public static <T, R> PageInfo<R> mapPage(PageInfo<T> page, Function<List<T>, List<R>> function) {
    PageInfo<R> resultPage = new PageInfo<>();
    resultPage.setList(function.apply(page.getList()));
    resultPage.setSize(page.getSize());
    resultPage.setPageNum(page.getPageNum());
    resultPage.setPageSize(page.getPageSize());
    resultPage.setStartRow(page.getStartRow());
    resultPage.setEndRow(page.getEndRow());
    resultPage.setTotal(page.getTotal());
    resultPage.setHasPreviousPage(page.isHasPreviousPage());
    resultPage.setHasNextPage(page.isHasNextPage());
    resultPage.setIsFirstPage(page.isIsFirstPage());
    resultPage.setIsLastPage(page.isIsLastPage());
    resultPage.setPages(page.getPages());
    resultPage.setPrePage(page.getPrePage());
    resultPage.setNextPage(page.getNextPage());
    resultPage.setNavigatePages(page.getNavigatePages());
    resultPage.setNavigatepageNums(page.getNavigatepageNums());
    resultPage.setNavigateFirstPage(page.getNavigateFirstPage());
    resultPage.setNavigateLastPage(page.getNavigateLastPage());
    return resultPage;
}
 
Example 5
Source File: ExamRecordService.java    From spring-microservice-exam with MIT License 4 votes vote down vote up
/**
 * 获取分页数据
 *
 * @param pageNum    pageNum
 * @param pageSize   pageSize
 * @param sort       sort
 * @param order      order
 * @param examRecord examRecord
 * @return PageInfo
 * @author tangyi
 * @date 2018/11/10 21:33
 */
   public PageInfo<ExaminationRecordDto> examRecordList(ExaminationRecord examRecord, String pageNum, String pageSize, String sort, String order) {
	examRecord.setTenantCode(SysUtil.getTenantCode());
	PageInfo<ExaminationRecordDto> examRecordDtoPageInfo = new PageInfo<>();
	List<ExaminationRecordDto> examRecordDtoList = new ArrayList<>();
	// 查询考试记录
	PageInfo<ExaminationRecord> examRecordPageInfo = this.findPage(
			PageUtil.pageInfo(pageNum, pageSize, sort, order), examRecord);
	if (CollectionUtils.isNotEmpty(examRecordPageInfo.getList())) {
		// 查询考试信息
		List<Examination> examinations = examinationService.findListById(examRecordPageInfo.getList().stream().map(ExaminationRecord::getExaminationId).distinct().toArray(Long[]::new));
		examRecordPageInfo.getList().forEach(tempExamRecord -> {
			// 找到考试记录所属的考试信息
			Examination examinationRecordExamination = examinations.stream()
					.filter(tempExamination -> tempExamRecord.getExaminationId().equals(tempExamination.getId()))
					.findFirst().orElse(null);
			// 转换成ExamRecordDto
			if (examinationRecordExamination != null) {
				ExaminationRecordDto examRecordDto = new ExaminationRecordDto();
				BeanUtils.copyProperties(examinationRecordExamination, examRecordDto);
				examRecordDto.setId(tempExamRecord.getId());
				examRecordDto.setStartTime(tempExamRecord.getStartTime());
				examRecordDto.setEndTime(tempExamRecord.getEndTime());
				examRecordDto.setScore(tempExamRecord.getScore());
				examRecordDto.setUserId(tempExamRecord.getUserId());
				examRecordDto.setExaminationId(tempExamRecord.getExaminationId());
				// 正确题目数
				examRecordDto.setCorrectNumber(tempExamRecord.getCorrectNumber());
				examRecordDto.setInCorrectNumber(tempExamRecord.getInCorrectNumber());
				// 提交状态
				examRecordDto.setSubmitStatus(tempExamRecord.getSubmitStatus());
				examRecordDtoList.add(examRecordDto);
			}
		});
		this.fillExamUserInfo(examRecordDtoList, examRecordPageInfo.getList().stream().map(ExaminationRecord::getUserId).distinct().toArray(Long[]::new));
	}
	examRecordDtoPageInfo.setTotal(examRecordPageInfo.getTotal());
	examRecordDtoPageInfo.setPages(examRecordPageInfo.getPages());
	examRecordDtoPageInfo.setPageSize(examRecordPageInfo.getPageSize());
	examRecordDtoPageInfo.setPageNum(examRecordPageInfo.getPageNum());
	examRecordDtoPageInfo.setList(examRecordDtoList);
	return examRecordDtoPageInfo;
}
 
Example 6
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;
}