Java Code Examples for org.springframework.data.domain.Page#getSize()
The following examples show how to use
org.springframework.data.domain.Page#getSize() .
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: ActionStatusMsgBeanQuery.java From hawkbit with Eclipse Public License 1.0 | 6 votes |
/** * Creates a list of {@link ProxyActionStatus} for presentation layer from * page of {@link ActionStatus}. * * @param actionBeans * page of {@link ActionStatus} * @return list of {@link ProxyActionStatus} */ private List<ProxyMessage> createProxyMessages(final Page<String> messages) { final List<ProxyMessage> proxyMsgs = new ArrayList<>(messages.getNumberOfElements()); Long idx = messages.getNumber() * ((long) messages.getSize()); for (final String msg : messages) { idx++; final ProxyMessage proxyMsg = new ProxyMessage(); proxyMsg.setMessage(msg); proxyMsg.setId(String.valueOf(idx)); proxyMsgs.add(proxyMsg); } if (messages.getTotalElements() == 1L && StringUtils.isEmpty(proxyMsgs.get(0).getMessage())) { proxyMsgs.get(0).setMessage(noMessageText); } return proxyMsgs; }
Example 2
Source File: ContactService.java From production-ready-microservices-starter with MIT License | 6 votes |
/** * Gets pageable contacts. * * @param pageable the pageable * @return the contact page */ @Transactional(readOnly = true) public ContactsResponse getContacts(Pageable pageable) { Page<Contact> contactPage = contactRepository.findAllByCreatedBy(getLoggedInUsername(), pageable); long totalElements = contactPage.getTotalElements(); int totalPage = contactPage.getTotalPages(); int size = contactPage.getSize(); int page = contactPage.getNumber(); List<ContactResponse> contactResponseList = new ArrayList<>(); for (Contact contact : contactPage.getContent()) { contactResponseList.add(buildContactResponse(contact)); } return ContactsResponse.builder() .items(contactResponseList) .page(page) .size(size) .totalPages(totalPage) .totalElements(totalElements) .build(); }
Example 3
Source File: TagServiceImpl.java From production-ready-microservices-starter with MIT License | 6 votes |
@Override public TagsResponse getTags(String siteId, Pageable pageable) { Page<Tag> tagPage = tagRepository.findAllByCreatedBy(pageable, getLoggedInUsername()); long totalElements = tagPage.getTotalElements(); int totalPage = tagPage.getTotalPages(); int size = tagPage.getSize(); int page = tagPage.getNumber(); List<TagResponse> tagResponseList = new ArrayList<>(); for (Tag tag : tagPage.getContent()) { tagResponseList.add(buildTagResponse(tag)); } return TagsResponse.builder() .items(tagResponseList) .page(page) .size(size) .totalPages(totalPage) .totalElements(totalElements) .build(); }
Example 4
Source File: PhotoServiceImpl.java From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 | 6 votes |
@Override public PagedResponse<PhotoResponse> getAllPhotosByAlbum(Long albumId, int page, int size) { AppUtils.validatePageNumberAndSize(page, size); Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, AppConstants.CREATED_AT); Page<Photo> photos = photoRepository.findByAlbumId(albumId, pageable); List<PhotoResponse> photoResponses = new ArrayList<>(photos.getContent().size()); for (Photo photo : photos.getContent()) { photoResponses.add(new PhotoResponse(photo.getId(), photo.getTitle(), photo.getUrl(), photo.getThumbnailUrl(), photo.getAlbum().getId())); } return new PagedResponse<>(photoResponses, photos.getNumber(), photos.getSize(), photos.getTotalElements(), photos.getTotalPages(), photos.isLast()); }
Example 5
Source File: PhotoServiceImpl.java From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 | 6 votes |
@Override public PagedResponse<PhotoResponse> getAllPhotos(int page, int size) { AppUtils.validatePageNumberAndSize(page, size); Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, CREATED_AT); Page<Photo> photos = photoRepository.findAll(pageable); List<PhotoResponse> photoResponses = new ArrayList<>(photos.getContent().size()); for (Photo photo : photos.getContent()) { photoResponses.add(new PhotoResponse(photo.getId(), photo.getTitle(), photo.getUrl(), photo.getThumbnailUrl(), photo.getAlbum().getId())); } if (photos.getNumberOfElements() == 0) { return new PagedResponse<>(Collections.emptyList(), photos.getNumber(), photos.getSize(), photos.getTotalElements(), photos.getTotalPages(), photos.isLast()); } return new PagedResponse<>(photoResponses, photos.getNumber(), photos.getSize(), photos.getTotalElements(), photos.getTotalPages(), photos.isLast()); }
Example 6
Source File: AbstractConverter.java From abixen-platform with GNU Lesser General Public License v2.1 | 5 votes |
public final Page<Target> convertToPage(Page<Source> sourcePage, Map<String, Object> parameters) { final List<Target> targets = new ArrayList<>(sourcePage.getContent().size()); for (Source source : sourcePage) { targets.add(convert(source, parameters)); } final Pageable pageable = new PageRequest(sourcePage.getNumber(), sourcePage.getSize(), sourcePage.getSort()); return new PageImpl<>(targets, pageable, sourcePage.getTotalElements()); }
Example 7
Source File: GroupAjaxController.java From spring-boot with Apache License 2.0 | 5 votes |
/** * @param search 是否是搜索请求 * @param filters 通过 jqgrid search 查询,多个查询条件时,包含查询条件为 json 格式数据。_search = false 时,jqgrid 传递过来的参数没有 filters , 此时 filters 的值为 null * @param currentPageNo 当前页码 * @param pageSize 页面可显示行数 * @param sortParameter 用于排序的列名 ,启用 groups 时,此项复杂,需要特殊解析 * @param sortDirection 排序的方式desc/asc * @return jqgrid 展示所需要的 json 结构,通过 spring 自动完成 */ @RequestMapping(value = "/jqgrid-search", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) //注意 value /jqgrid-search ,不能为 /jqgrid-search/ ,不能多加后面的斜线 @ResponseBody public JqgridPage jqgridSearch( @RequestParam("_search") Boolean search, @RequestParam(value = "filters", required = false) String filters, @RequestParam(value = "page", required = true) Integer currentPageNo, @RequestParam(value = "rows", required = true) Integer pageSize, @RequestParam(value = "sidx", required = true) String sortParameter, @RequestParam(value = "sord", required = true) String sortDirection, RedirectAttributes redirectAttrs, HttpServletRequest request) { log.info("search ={},page ={},rows ={},sord={},sidx={},filters={}", search, currentPageNo, pageSize, sortDirection, sortParameter, filters); /** * 记录集 */ Page<GroupEntity> pages = JpaUtils.getJqGridPage(groupRepository, currentPageNo, pageSize, SqlUtils.createOrder(sortDirection,sortParameter), filters); if (pages.getTotalElements() == 0) return new JqgridPage(pageSize, 0, 0, new ArrayList(0)); //构造空数据集,否则返回结果集 jqgird 解析会有问题 /** * POJO to DTO * 转换原因见 service/package-info.java */ DtoUtils dtoUtils = new DtoUtils(); //用法见 DTOUtils // dtoUtils.addExcludes(MenuEntity.class, "parent"); //在整个转换过程中,无论哪个级联层次,只要遇到 TreeEntity 类,那么他的 parent 属性就不进行转换 dtoUtils.addExcludes(GroupEntity.class, "users", "roles"); JqgridPage<GroupEntity> jqPage = new JqgridPage (pages.getSize(), pages.getNumber(), (int) pages.getTotalElements(), dtoUtils.createDTOcopy(pages.getContent())); return jqPage; }
Example 8
Source File: PostServiceImpl.java From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 | 5 votes |
@Override public PagedResponse<Post> getPostsByCreatedBy(String username, int page, int size) { validatePageNumberAndSize(page, size); User user = userRepository.findByUsername(username) .orElseThrow(() -> new ResourceNotFoundException(USER, USERNAME, username)); Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, CREATED_AT); Page<Post> posts = postRepository.findByCreatedBy(user.getId(), pageable); List<Post> content = posts.getNumberOfElements() == 0 ? Collections.emptyList() : posts.getContent(); return new PagedResponse<>(content, posts.getNumber(), posts.getSize(), posts.getTotalElements(), posts.getTotalPages(), posts.isLast()); }
Example 9
Source File: PageInfo.java From graphql-java-demo with MIT License | 5 votes |
PageInfo(Page page) { this.totalElements = page.getTotalElements(); this.totalPages = page.getTotalPages(); this.numberOfElements = page.getNumberOfElements(); this.pageNumber = page.getNumber(); this.pageSize = page.getSize(); }
Example 10
Source File: CustomerListResourceAssembler.java From Showcase with Apache License 2.0 | 5 votes |
@PageLinks(CustomerController.class) public CustomerListResource build(Page<Customer> page) { List<CustomerResource> customerList = page.getContent() .stream() .map(customer -> customerResourceAssembler.toResource(customer)) .collect(Collectors.toList()); return new CustomerListResource(customerList, page.getNumber(), page.getSize(), page.getTotalPages(), page.getTotalElements()); }
Example 11
Source File: DTOUtils.java From angularjs-springmvc-sample-boot with Apache License 2.0 | 5 votes |
public static <S, T> Page<T> mapPage(Page<S> source, Class<T> targetClass) { List<S> sourceList = source.getContent(); List<T> list = new ArrayList<>(); for (int i = 0; i < sourceList.size(); i++) { T target = INSTANCE.map(sourceList.get(i), targetClass); list.add(target); } return new PageImpl<>(list, new PageRequest(source.getNumber(), source.getSize(), source.getSort()), source.getTotalElements()); }
Example 12
Source File: PageInfo.java From base-admin with MIT License | 5 votes |
/** * 获取统一分页对象 */ public static <M> PageInfo<M> of(Page page, Class<M> entityModelClass) { int records = (int) page.getTotalElements(); int pageSize = page.getSize(); int total = records % pageSize == 0 ? records / pageSize : records / pageSize + 1; PageInfo<M> pageInfo = new PageInfo<>(); pageInfo.setPage(page.getNumber() + 1);//页码 pageInfo.setPageSize(pageSize);//页面大小 pageInfo.setRows(CopyUtil.copyList(page.getContent(), entityModelClass));//分页结果 pageInfo.setRecords(records);//总记录数 pageInfo.setTotal(total);//总页数 return pageInfo; }
Example 13
Source File: BaseDomain.java From spring-microservice-boilerplate with MIT License | 5 votes |
/** * Get page of <T>. * * @param specification {@link Specification} * @param pageable pageable * @param voType VO of some class * @return page of <T> */ @SuppressWarnings("unchecked") public Page getPage(Specification<T> specification, Pageable pageable, Class voType) throws InstantiationException, IllegalAccessException { Page<T> poPage = repository.findAll(specification, pageable); if (poPage.getSize() == 0) { return null; } return transformer.poPage2VO(transformer.pos2VOs(voType, poPage.getContent()), pageable, poPage.getTotalElements()); }
Example 14
Source File: ViolationsController.java From fullstop with Apache License 2.0 | 5 votes |
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 15
Source File: PageInfo.java From springBoot with MIT License | 5 votes |
/** * 获取统一分页对象 */ public static <M> PageInfo<M> of(Page page, Class<M> entityModelClass) { int records = (int) page.getTotalElements(); int pageSize = page.getSize(); int total = records % pageSize == 0 ? records / pageSize : records / pageSize + 1; PageInfo<M> pageInfo = new PageInfo<>(); pageInfo.setPage(page.getNumber() + 1);//页码 pageInfo.setPageSize(pageSize);//页面大小 pageInfo.setRows(CopyUtil.copyList(page.getContent(), entityModelClass));//分页结果 pageInfo.setRecords(records);//总记录数 pageInfo.setTotal(total);//总页数 return pageInfo; }
Example 16
Source File: PlatformPageImpl.java From abixen-platform with GNU Lesser General Public License v2.1 | 5 votes |
public PlatformPageImpl(Page page) { super(page.getContent(), new PageRequest(page.getNumber(), page.getSize(), page.getSort()), page.getTotalElements()); this.number = page.getNumber(); this.size = page.getSize(); this.totalPages = page.getTotalPages(); this.numberOfElements = page.getNumberOfElements(); this.totalElements = page.getTotalElements(); this.first = page.isFirst(); this.last = page.isLast(); this.content = page.getContent(); this.sort = page.getSort(); }
Example 17
Source File: PageResp.java From ElementVueSpringbootCodeTemplate with Apache License 2.0 | 4 votes |
public PageResp(Page<T> page) { this.rows = page.getContent(); this.page = page.getNumber() + 1; this.pagesize = page.getSize(); this.total = page.getTotalElements(); }
Example 18
Source File: AlbumServiceImpl.java From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 | 4 votes |
@Override public PagedResponse<AlbumResponse> getAllAlbums(int page, int size){ AppUtils.validatePageNumberAndSize(page, size); Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, CREATED_AT); Page<Album> albums = albumRepository.findAll(pageable); if (albums.getNumberOfElements() == 0){ return new PagedResponse<>(Collections.emptyList(), albums.getNumber(), albums.getSize(), albums.getTotalElements(), albums.getTotalPages(), albums.isLast()); } List<AlbumResponse> albumResponses = Arrays.asList(modelMapper.map(albums.getContent(), AlbumResponse[].class)); return new PagedResponse<>(albumResponses, albums.getNumber(), albums.getSize(), albums.getTotalElements(), albums.getTotalPages(), albums.isLast()); }
Example 19
Source File: PostServiceImpl.java From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 | 3 votes |
@Override public PagedResponse<Post> getPostsByTag(Long id, int page, int size) { AppUtils.validatePageNumberAndSize(page, size); Tag tag = tagRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException(TAG, ID, id)); Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, CREATED_AT); Page<Post> posts = postRepository.findByTags(Arrays.asList(tag), pageable); List<Post> content = posts.getNumberOfElements() == 0 ? Collections.emptyList() : posts.getContent(); return new PagedResponse<>(content, posts.getNumber(), posts.getSize(), posts.getTotalElements(), posts.getTotalPages(), posts.isLast()); }
Example 20
Source File: PageUtil.java From beihu-boot with Apache License 2.0 | 2 votes |
/** * 构建分页返回结果 * * @param data * @param page * @param <T> * @return */ public static <T> PageResult<T> pageResult(List<T> data, Page page) { return new PageResult<>(data, page.getNumber() + 1, page.getSize(), page.getTotalElements()); }