Java Code Examples for org.springframework.data.domain.Page#getTotalElements()

The following examples show how to use org.springframework.data.domain.Page#getTotalElements() . 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: PostsController.java    From expper with GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping(value = "posts/search", method = RequestMethod.GET)
@Timed
public String search(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "", name = "q") String query, Model model) {
    page = page < 1 ? 1 : page - 1;
    long totalElements = 0l;

    if (!query.trim().isEmpty()) {
        String q = query.trim().toLowerCase().replaceAll("\\s", "+");
        Page<Post> posts = postSearchRepository.findByTitleLikeAndStatus(q, PostStatus.PUBLIC, new PageRequest(page, PAGE_SIZE));
        List<Post> content = posts.getContent();
        model.addAttribute("posts", content);
        model.addAttribute("totalPages", posts.getTotalPages());
        model.addAttribute("votes", voteService.getCurrentUserVoteMapFor(content));
        model.addAttribute("counting", countingService.getPostListCounting(content));
        totalElements = posts.getTotalElements();
    }

    model.addAttribute("totalElements", totalElements);
    model.addAttribute("query", query);
    model.addAttribute("page", page + 1);

    return "posts/search";
}
 
Example 2
Source File: AuthorDTOService.java    From celerio-angular-quickstart with Apache License 2.0 6 votes vote down vote up
@Transactional(readOnly = true)
public PageResponse<AuthorDTO> findAll(PageRequestByExample<AuthorDTO> req) {
    Example<Author> example = null;
    Author author = toEntity(req.example);

    if (author != null) {
        ExampleMatcher matcher = ExampleMatcher.matching() //
                .withMatcher(Author_.lastName.getName(), match -> match.ignoreCase().startsWith())
                .withMatcher(Author_.firstName.getName(), match -> match.ignoreCase().startsWith())
                .withMatcher(Author_.email.getName(), match -> match.ignoreCase().startsWith());

        example = Example.of(author, matcher);
    }

    Page<Author> page;
    if (example != null) {
        page = authorRepository.findAll(example, req.toPageable());
    } else {
        page = authorRepository.findAll(req.toPageable());
    }

    List<AuthorDTO> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
    return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
}
 
Example 3
Source File: PassportDTOService.java    From celerio-angular-quickstart with Apache License 2.0 6 votes vote down vote up
@Transactional(readOnly = true)
public PageResponse<PassportDTO> findAll(PageRequestByExample<PassportDTO> req) {
    Example<Passport> example = null;
    Passport passport = toEntity(req.example);

    if (passport != null) {
        ExampleMatcher matcher = ExampleMatcher.matching() //
                .withMatcher(Passport_.passportNumber.getName(), match -> match.ignoreCase().startsWith());

        example = Example.of(passport, matcher);
    }

    Page<Passport> page;
    if (example != null) {
        page = passportRepository.findAll(example, req.toPageable());
    } else {
        page = passportRepository.findAll(req.toPageable());
    }

    List<PassportDTO> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
    return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
}
 
Example 4
Source File: PostsController.java    From JavaQuarkBBS with Apache License 2.0 6 votes vote down vote up
@GetMapping
public PageResult getAll(Posts posts, Integer uid, String draw,
                         @RequestParam(required = false, defaultValue = "1") int start,
                         @RequestParam(required = false, defaultValue = "10") int length) {
    int pageNo = start / length;
    if (uid != null) {
        User user = userService.findOne(uid);
        posts.setUser(user);
    }
    Page<Posts> page = postsService.findByPage(posts, pageNo, length);
    PageResult<List<Posts>> result = new PageResult<>(
            draw,
            page.getTotalElements(),
            page.getTotalElements(),
            page.getContent());
    return result;
}
 
Example 5
Source File: ArchivedUserRestSupportImpl.java    From spring-backend-boilerplate with Apache License 2.0 5 votes vote down vote up
@Override
public Page<UserSummary> listArchivedUsers(UserQueryParameter queryRequest) {
	queryRequest.setEnabled(null);
	Page<User> userPage = accountService.listArchivedUsers(queryRequest);
	return new PageImpl<>(userPage.getContent().stream().map(UserSummary::from).collect(Collectors.toList()),
						  new PageRequest(queryRequest.getStart(), queryRequest.getLimit()),
						  userPage.getTotalElements());
}
 
Example 6
Source File: RoleServiceImpl.java    From spring-backend-boilerplate with Apache License 2.0 5 votes vote down vote up
@Override
public Page<User> listBindUsers(String id, UserQueryRequest request) {
	AppRole appRole = findById(id);
	Page<UserRoleRelationship> relationships = relationshipRepository.findByRole(appRole,
																				 new PageRequest(request.getStart(),
																									request.getLimit()));
	return new PageImpl<>(relationships.getContent()
									   .stream()
									   .map(UserRoleRelationship::getUser)
									   .collect(Collectors.toList()),
						  new PageRequest(request.getStart(), request.getLimit()),
						  relationships.getTotalElements());
}
 
Example 7
Source File: PermissionController.java    From itweet-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 资源列表
 * @param model
 * @return
 */
@LeftMenu(name = "资源列表",descritpion = "admin_permission_list",pname = "资源管理",url = "/admin/permission/list",operation = "list")
@RequestMapping(value = "/list",method = RequestMethod.GET)
public String list(@RequestParam(value = "page", defaultValue = "0") Integer page,Model model) {

    if(page !=0) page = page -1;

    Page<SysPermission> permissionList = permissionService.list(page);
    model.addAttribute("permissionList",permissionList);

    PageUtils pageUtils = new PageUtils("/admin/permission/list?",page,permissionList.getTotalPages(),permissionList.getTotalElements(),itweetProperties.getPagSize());
    model.addAttribute("pb",pageUtils);

    return "admin/user/p_list";
}
 
Example 8
Source File: CheckController.java    From logistics-back with MIT License 5 votes vote down vote up
/**
 * 查询所有营业外收入
 */
   @RequestMapping(value = "/selectExtraIncome", method = RequestMethod.GET)
public Result selectAllExtra(@RequestParam("pageNum") int pageNum, @RequestParam("limit") int limit) {
	Pageable pageable = PageRequest.of(pageNum-1, limit);
	Page<ExtraIncome> page = checkService.selectAllExtra(pageable);
	Result result  = new Result(200, "SUCCESS", (int) page.getTotalElements(), page.getContent());
	return result;	
}
 
Example 9
Source File: RoleController.java    From JavaQuarkBBS with Apache License 2.0 5 votes vote down vote up
@GetMapping
public PageResult getAll(String draw,
                         @RequestParam(required = false, defaultValue = "1") int start,
                         @RequestParam(required = false, defaultValue = "10") int length) {
    int pageNo = start / length;
    Page<Role> page = roleService.findByPage(pageNo, length);
    PageResult<List<Role>> result = new PageResult<>(
            draw,
            page.getTotalElements(),
            page.getTotalElements(),
            page.getContent());

    return result;
}
 
Example 10
Source File: ViolationsController.java    From fullstop with Apache License 2.0 5 votes vote down vote up
private Page<Violation> mapBackendToFrontendViolations(final Page<ViolationEntity> backendViolations) {
    final PageRequest currentPageRequest = new PageRequest(
            backendViolations.getNumber(),
            backendViolations.getSize(),
            backendViolations.getSort());
    return new PageImpl<>(
            backendViolations.getContent().stream().map(entityToDto::convert).collect(toList()),
            currentPageRequest,
            backendViolations.getTotalElements());
}
 
Example 11
Source File: SysRoleRestSupportImpl.java    From spring-backend-boilerplate with Apache License 2.0 5 votes vote down vote up
@Override
public Page<RoleSummary> getAppRoles(RoleQueryRequest request) {
	Page<AppRole> appRoles = appRoleService.listAppRoles(request);
	return new PageImpl<>(appRoles.getContent().stream().map(RoleSummary::from).collect(Collectors.toList()),
						  new PageRequest(request.getStart(), request.getLimit()),
						  appRoles.getTotalElements());
}
 
Example 12
Source File: TagServiceImpl.java    From mblog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Page<TagVO> pagingQueryTags(Pageable pageable) {
    Page<Tag> page = tagRepository.findAll(pageable);

    Set<Long> postIds = new HashSet<>();
    List<TagVO> rets = page.getContent().stream().map(po -> {
        postIds.add(po.getLatestPostId());
        return BeanMapUtils.copy(po);
    }).collect(Collectors.toList());

    Map<Long, PostVO> posts = postService.findMapByIds(postIds);
    rets.forEach(n -> n.setPost(posts.get(n.getLatestPostId())));
    return new PageImpl<>(rets, pageable, page.getTotalElements());
}
 
Example 13
Source File: AlbumServiceImpl.java    From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public PagedResponse<Album> getUserAlbums(String username, int page, int size){
       User user = userRepository.findByUsername(username).orElseThrow(() -> new ResourceNotFoundException(USER_STR, USERNAME_STR, username));
       Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, CREATED_AT);

       Page<Album> albums = albumRepository.findByCreatedBy(user.getId(), pageable);
       
       List<Album> content = albums.getNumberOfElements() > 0 ? albums.getContent() : Collections.emptyList();
       
       return new PagedResponse<>(content, albums.getNumber(), albums.getSize(), albums.getTotalElements(), albums.getTotalPages(), albums.isLast());
   }
 
Example 14
Source File: PaginationUtils.java    From spring-cloud-gray with Apache License 2.0 4 votes vote down vote up
public static <MODEL, T> Page<MODEL> convert(Pageable pageable, Page<T> p, ModelMapper<MODEL, T> modelMapper) {
    List<MODEL> list = modelMapper.dos2models(p.getContent());
    return new PageImpl<MODEL>(list, pageable, p.getTotalElements());
}
 
Example 15
Source File: JPAServiceManageModule.java    From spring-cloud-gray with Apache License 2.0 4 votes vote down vote up
@Override
public Page<String> listAllUserServiceIds(Pageable pageable) {
    Page<UserServiceAuthority> entities = listAllUserServiceAuthorities(pageable);
    List<String> serviceIds = entities.getContent().stream().map(UserServiceAuthority::getServiceId).collect(Collectors.toList());
    return new PageImpl<>(serviceIds, pageable, entities.getTotalElements());
}
 
Example 16
Source File: JpaRolloutGroupManagement.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
private static Page<Target> convertTPage(final Page<JpaTarget> findAll, final Pageable pageable) {
    return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
 
Example 17
Source File: JpaDistributionSetTypeManagement.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
private static Page<DistributionSetType> convertPage(final Page<JpaDistributionSetType> findAll,
        final Pageable pageable) {
    return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
 
Example 18
Source File: JpaRolloutGroupManagement.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
private static Page<RolloutGroup> convertPage(final Page<JpaRolloutGroup> findAll, final Pageable pageable) {
    return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
 
Example 19
Source File: CommunityServiceImpl.java    From cloudstreetmarket.com with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Page<UserActivityDTO> getPublicActivity(Pageable pageable) {
	Page<Action> actions = actionRepository.findAll(pageable);
	List<UserActivityDTO> result = transform(actions);
	return new PageImpl<>(result, pageable, actions.getTotalElements());
}
 
Example 20
Source File: InvestServiceImpl.java    From hermes with Apache License 2.0 4 votes vote down vote up
@Override
public Page<InvestInfo> findByUser(final User user,final List<String> loanKindList,Integer page, Integer size) {
	Pageable pageable = Pageables.pageable(page, size);
	List<InvestInfo> investinfoList = new ArrayList<InvestInfo>();
	Page<Invest> investList = investRepository.findAll(new Specification<Invest>() {			
		@Override
		public Predicate toPredicate(Root<Invest> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
			Predicate p1 = root.get("loan").get("loanKind").in(loanKindList);
			Predicate p2 = cb.equal(root.get("user"), user) ;				
			return cb.and(p1,p2);
		}
	}, pageable);		
	InvestInfo investInfo = null;
	for (Invest invest : investList) {
		investInfo = new InvestInfo();
		investInfo.setId(invest.getId());
		String purpose = "";
		String loanStatus = invest.getLoan().getLoanKind();
		if (Loan.LoanKinds.NORML_LOAN.equals(loanStatus)) {
			purpose = getDictionaryName(invest.getLoan().getPurpose());
		} else {
			purpose = invest.getLoan().getPurpose();
		}
		investInfo.setPurpose(purpose);
		investInfo.setRate(invest.getLoan().getRateFormat());
		investInfo.setAmount(invest.getAmount());
		investInfo.setPeriod(invest.getLoan().getPeriod());
		investInfo.setStatus(invest.getStatus());
		investInfo.setLoanKind(loanStatus);
		investInfo.setLoanNo(invest.getLoan().getLoanNo());
		List<InvestProfit> investProfitList = investProfitRepository.findByInvest(invest);
		BigDecimal shouldReceivePI = BigDecimal.ZERO;
		BigDecimal receivedPI = BigDecimal.ZERO;
		BigDecimal waitReceivePI = BigDecimal.ZERO;
		for (InvestProfit investProfit : investProfitList) {
			shouldReceivePI = shouldReceivePI.add(investProfit.getAmount());
			// 待收本息
			if (InvestProfit.Status.WAIT.equals(investProfit.getStatus())) {
				waitReceivePI = waitReceivePI.add(investProfit.getAmount());
			} else {
				receivedPI = receivedPI.add(investProfit.getPrincipal()).add(investProfit.getInterest());
			}
		}
		investInfo.setShouldReceivePI(Numbers.toCurrency(shouldReceivePI.doubleValue()));
		investInfo.setWaitReceivePI(Numbers.toCurrency(waitReceivePI.doubleValue()));
		investInfo.setReceivedPI(Numbers.toCurrency(receivedPI.doubleValue()));
		JlfexOrder jlfexOrder = jlfexOrderService.findByInvest(invest.getId());
		if(jlfexOrder!=null){
		   investInfo.setLoanPdfId(jlfexOrder.getLoanPdfId());
		   investInfo.setGuaranteePdfId(jlfexOrder.getGuaranteePdfId());
		}
		investinfoList.add(investInfo);
	}
	Page<InvestInfo> pageInvest = new PageImpl<InvestInfo>(investinfoList, pageable, investList.getTotalElements());
	return pageInvest;
}