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

The following are Jave code examples for showing how to use getTotalElements() of the org.springframework.data.domain.Page class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: xq_seckill_microservice   File: EstateServiceImpl.java   Source Code and License Vote up 7 votes
@Override
@Transactional(readOnly = true)
public Page<EstateItemDTO> listForSaleByPage(Pageable pageable, Map<String, Object> paramMap) throws Exception {
    String cacheKey = CacheKeyGenerator.generate(EstateItemDTO.class, "listForSaleByPage", pageable, paramMap);

    Page<EstateItemDTO> targetItemPage = new PageX();

    // 读取缓存数据
    targetItemPage = byteRedisClient.getByteObj(cacheKey, targetItemPage.getClass());
    if (targetItemPage != null && CollectionUtils.isNotEmpty(targetItemPage.getContent())) {
        return new PageX(targetItemPage.getContent(), pageable, targetItemPage.getTotalElements());
    } else {
        Page<EstateItemModel> sourceItemPage = estateItemRepository.findAll(EstateItemSpecification.getForSaleSpec(paramMap), pageable);
        List<EstateItemModel> sourceItemList = sourceItemPage.getContent();

        if (CollectionUtils.isNotEmpty(sourceItemList)) {
            List<EstateItemDTO> targetItemList = new ArrayList();
            for (EstateItemModel model : sourceItemList) {
                EstateItemDTO dto = new EstateItemDTO();
                CachedBeanCopier.copy(model, dto);
                if (StringUtils.isBlank(dto.getCoverUrl())) dto.setCoverUrl("/3rd-party/porto/img/blank.jpg");
                dto.setDetailHref("/estate/" + dto.getHouseCode() + ".shtml");
                dto.setTotalPriceStr(dto.getTotalPrice() + "万");
                dto.setUnitPriceStr("单价" + dto.getUnitPrice() + "万");
                dto.setDownPayments(dto.getUnitPriceStr() + ", 首付" + BigDecimal.valueOf(0.3d).multiply(dto.getTotalPrice()).setScale(2, BigDecimal.ROUND_HALF_DOWN) + "万");
                dto.setAreaStr(dto.getArea() + "平米");
                dto.setFocusNumStr(dto.getFocusNum() + "人关注");
                dto.setWatchNumStr(dto.getWatchNum() + "次带看");
                dto.setNewEstate(dto.getUpdateTime().isAfter(TimeUtil.nowDateTime().minusDays(3))); // 是当前日期三天前发布的
                targetItemList.add(dto);
            }
            targetItemPage = new PageX(targetItemList, pageable, sourceItemPage.getTotalElements());

            // 数据写入缓存
            byteRedisClient.setByteObj(cacheKey, targetItemPage, 3600);
        }

        return targetItemPage;
    }
}
 
Example 2
Project: JavaQuarkBBS   File: ReplyController.java   Source Code and License Vote up 7 votes
@GetMapping
public PageResult getAll(Reply reply, 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);
        reply.setUser(user);
    }

    Page<Reply> page = replyService.findByPage(reply, pageNo, length);
    PageResult<List<Reply>> result = new PageResult<>(
            draw,
            page.getTotalElements(),
            page.getTotalElements(),
            page.getContent());
    return result;
}
 
Example 3
Project: apollo-custom   File: InstanceConfigController.java   Source Code and License Vote up 6 votes
@RequestMapping(value = "/by-namespace", method = RequestMethod.GET)
public PageDTO<InstanceDTO> getInstancesByNamespace(
    @RequestParam("appId") String appId, @RequestParam("clusterName") String clusterName,
    @RequestParam("namespaceName") String namespaceName,
    @RequestParam(value = "instanceAppId", required = false) String instanceAppId,
    Pageable pageable) {
  Page<Instance> instances;
  if (Strings.isNullOrEmpty(instanceAppId)) {
    instances = instanceService.findInstancesByNamespace(appId, clusterName,
        namespaceName, pageable);
  } else {
    instances = instanceService.findInstancesByNamespaceAndInstanceAppId(instanceAppId, appId,
        clusterName, namespaceName, pageable);
  }

  List<InstanceDTO> instanceDTOs = BeanUtils.batchTransform(InstanceDTO.class, instances.getContent());
  return new PageDTO<>(instanceDTOs, pageable, instances.getTotalElements());
}
 
Example 4
Project: springboot-jsp-generator   File: DictionaryController.java   Source Code and License Vote up 6 votes
@RequestMapping(path="/list")
	public String list(DictionarySearchCriteria criteria
			, Map<String, Object> model) {
		// setting default pageSize and sortFields
		if (criteria.isFirstInitialized()) {
			criteria.setPageSize(10);
			criteria.setSortFields("id:asc");
		}
//		logger.info("----------------------{}-------------------------", DictionaryType.PREDEFINED);
		Page<Dictionary> searchResult = this.dictionaryService.findAll(criteria.getPageable());
		Pagination pagination = new Pagination(criteria.getPageNo(), searchResult.getTotalPages(), searchResult.getTotalElements());
		model.put("searchResult", searchResult);
		model.put("criteria", criteria);
		model.put("pagination", pagination);
		return "tool/dictionary_list";
	}
 
Example 5
Project: itweet-boot   File: TwtsController.java   Source Code and License Vote up 6 votes
@GetMapping(value = "/blog")
public String index(@RequestParam(value = "page", defaultValue = "0") Integer page,Model model) {
    if(page != 0) page = page -1;

    List<ArticleDto> topArticle = articleService.getArticleRecentPostsTopN(5);
    model.addAttribute("topArticle",topArticle);

    Page<ArticleDto> listArticle = articleService.list(page, ArticleUtils.getIsPublished());
    model.addAttribute("listArticle",listArticle.getContent());

    List<CategoriesDto> categoriesList = categoriesService.getCategoriesArticleCount();
    model.addAttribute("categoriesList",categoriesList);

    PageUtils pageUtils = new PageUtils("/blog?",page,listArticle.getTotalPages(),listArticle.getTotalElements(),itweetProperties.getPagSize());
    model.addAttribute("pb",pageUtils);

    return "front/theme/twts/index";
}
 
Example 6
Project: os   File: GenericService.java   Source Code and License Vote up 5 votes
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
public <DTO extends IGenericDTO<PK>> Page<DTO> findAll(Class<DTO> dtoClass, Specification<E> spec,
		Pageable pageable) throws Exception {
	Page<E> sp = findAll(spec, pageable);
	Page<DTO> dp = new PageImpl<DTO>(BeanMapper.map(sp.getContent(), dtoClass), pageable, sp.getTotalElements());
	return dp;
}
 
Example 7
Project: JavaQuarkBBS   File: PermissionController.java   Source Code and License Vote up 5 votes
@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<Permission> page = permissionService.findByPage(pageNo, length);
    PageResult<List<Permission>> result = new PageResult<>(
            draw,
            page.getTotalElements(),
            page.getTotalElements(),
            page.getContent());

    return result;
}
 
Example 8
Project: spring-backend-boilerplate   File: SysRoleRestSupportImpl.java   Source Code and License Vote up 5 votes
@Override
public Page<UserSummary> getUsersByAppRoleId(String roleId, UserQueryParameter request) {
	Page<User> users = appRoleService.listBindUsers(roleId, request);
	return new PageImpl<>(users.getContent().stream().map(UserSummary::from).collect(Collectors.toList()),
						  new PageRequest(request.getStart(), request.getLimit()),
						  users.getTotalElements());
}
 
Example 9
Project: spring-backend-boilerplate   File: ArchivedUserRestSupportImpl.java   Source Code and License Vote up 5 votes
@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 10
Project: fat-lining   File: WeightMeasurementsController.java   Source Code and License Vote up 5 votes
@GetMapping("all")
public String all(@RequestParam(value = "page", defaultValue = "0") int pageNumber, Model model) {
	if (pageNumber < 0) {
		return "redirect:/measurements/all?page=0";
	} else {
		Page<WeightMeasurement> page = measurementsManager.findAsPageDesc(pageNumber, paginationConfig.getPageSize());
		if (pageNumber >= page.getTotalPages() && page.getTotalElements() > 0) {
			return "redirect:/measurements/all?page=0";
		} else {
			model.addAttribute(FatLiningConstants.FIELD_PAGE, pageWrapperFactory.create(page));
			return FatLiningConstants.VIEW_MEASUREMENTS;
		}
	}
}
 
Example 11
Project: spring-backend-boilerplate   File: SysRoleRestSupportImpl.java   Source Code and License Vote up 5 votes
@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
Project: spring-backend-boilerplate   File: RoleServiceImpl.java   Source Code and License Vote up 5 votes
@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 13
Project: spring-backend-boilerplate   File: AppRoleRestSupportImpl.java   Source Code and License Vote up 5 votes
@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 14
Project: itweet-boot   File: ArticleController.java   Source Code and License Vote up 5 votes
/**
 *文章列表
 * @param page
 * @param pageSize
 * @param model
 * @return
 */
@RequestMapping(value = "/list",method = RequestMethod.GET)
public String list(@RequestParam(value = "page", defaultValue = "0") Integer page, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, Model model) {
    if(page !=0) page = page -1;

    Page<ArticleDto> articleList = articleService.list(page);
    model.addAttribute("articleList",articleList);

    PageUtils pageUtils = new PageUtils("/admin/article/list?",page,articleList.getTotalPages(),articleList.getTotalElements(),pageSize);
    model.addAttribute("pb",pageUtils);

    return "admin/article/a_list";
}
 
Example 15
Project: spring-backend-boilerplate   File: AppRoleRestSupportImpl.java   Source Code and License Vote up 5 votes
@Override
public Page<UserSummary> getUsersByAppRoleId(String roleId, UserQueryParameter request) {
	Page<User> users = appRoleService.listBindUsers(roleId, request);
	return new PageImpl<>(users.getContent().stream().map(UserSummary::from).collect(Collectors.toList()),
						  new PageRequest(request.getStart(), request.getLimit()),
						  users.getTotalElements());
}
 
Example 16
Project: SpringBoot_Wechat_Sell   File: OrderServiceImpl.java   Source Code and License Vote up 5 votes
@Override
public Page<OrderDTO> findListAll(Pageable pageable) {
    Page<OrderMaster> orderMasterPage = orderMasterRepository.findAll(pageable);
    List<OrderDTO> orderDTOList = OrderMasterToOrderDTOConverter.convert(orderMasterPage.getContent());
    return new PageImpl<OrderDTO>(orderDTOList, pageable, orderMasterPage.getTotalElements());

}
 
Example 17
Project: itweet-boot   File: EffeController.java   Source Code and License Vote up 5 votes
@GetMapping(value = "/tweet")
public String tweet(@RequestParam(value = "page", defaultValue = "0") Integer page,Model model) {
    if(page != 0) page = page -1;

    model.addAttribute("tweet","selected");
    Page<ArticleDto> listArticle = articleService.list(page, ArticleUtils.getIsPublished(),ArticleUtils.getIsTweet());
    model.addAttribute("listArticle",listArticle);

    PageUtils pageUtils = new PageUtils("/tweet",page,listArticle.getTotalPages(),listArticle.getTotalElements(),itweetProperties.getPagSize());
    model.addAttribute("pb",pageUtils);

    return "front/theme/effe/tweet";
}
 
Example 18
Project: va-vedem-api   File: PrimariiAPI.java   Source Code and License Vote up 5 votes
@RequestMapping(value = "/searchCityHalls")
@ResponseBody
public Page<PrimarieModel> searchCityHall(@ModelAttribute SearchCityHallParameters searchParameters, Pageable pageable) {
    // get a page of DB entities
    Page<Primarie> primaries = primarieCRUDRepository.findByJudetCode(
            !StringUtils.isEmpty(searchParameters.getCountyCode()) ?
                    searchParameters.getCountyCode() : "BV", pageable);

    Type targetListType = new TypeToken<List<PrimarieModel>>() {
    }.getType();

    // convert the DB entities to presentation objects
    return new PageImpl<>(modelMapper.map(primaries.getContent(), targetListType), pageable, primaries.getTotalElements());
}
 
Example 19
Project: multi-tenant-rest-api   File: CompanyMapper.java   Source Code and License Vote up 4 votes
public static Page<CompanyDTO> mapEntityPageIntoDTOPage(Pageable page, Page<CompanyEntity> source) {
    List<CompanyDTO> dtos = mapEntitiesIntoDTOs(source.getContent());
    return new PageImpl<>(dtos, page, source.getTotalElements());
}
 
Example 20
Project: apollo-custom   File: InstanceConfigController.java   Source Code and License Vote up 4 votes
@RequestMapping(value = "/by-release", method = RequestMethod.GET)
public PageDTO<InstanceDTO> getByRelease(@RequestParam("releaseId") long releaseId,
                                         Pageable pageable) {
  Release release = releaseService.findOne(releaseId);
  if (release == null) {
    throw new NotFoundException(String.format("release not found for %s", releaseId));
  }
  Page<InstanceConfig> instanceConfigsPage = instanceService.findActiveInstanceConfigsByReleaseKey
      (release.getReleaseKey(), pageable);

  List<InstanceDTO> instanceDTOs = Collections.emptyList();

  if (instanceConfigsPage.hasContent()) {
    Multimap<Long, InstanceConfig> instanceConfigMap = HashMultimap.create();
    Set<String> otherReleaseKeys = Sets.newHashSet();

    for (InstanceConfig instanceConfig : instanceConfigsPage.getContent()) {
      instanceConfigMap.put(instanceConfig.getInstanceId(), instanceConfig);
      otherReleaseKeys.add(instanceConfig.getReleaseKey());
    }

    Set<Long> instanceIds = instanceConfigMap.keySet();

    List<Instance> instances = instanceService.findInstancesByIds(instanceIds);

    if (!CollectionUtils.isEmpty(instances)) {
      instanceDTOs = BeanUtils.batchTransform(InstanceDTO.class, instances);
    }

    for (InstanceDTO instanceDTO : instanceDTOs) {
      Collection<InstanceConfig> configs = instanceConfigMap.get(instanceDTO.getId());
      List<InstanceConfigDTO> configDTOs = configs.stream().map(instanceConfig -> {
        InstanceConfigDTO instanceConfigDTO = new InstanceConfigDTO();
        //to save some space
        instanceConfigDTO.setRelease(null);
        instanceConfigDTO.setReleaseDeliveryTime(instanceConfig.getReleaseDeliveryTime());
        instanceConfigDTO.setDataChangeLastModifiedTime(instanceConfig
            .getDataChangeLastModifiedTime());
        return instanceConfigDTO;
      }).collect(Collectors.toList());
      instanceDTO.setConfigs(configDTOs);
    }
  }

  return new PageDTO<>(instanceDTOs, pageable, instanceConfigsPage.getTotalElements());
}