Java Code Examples for org.springframework.data.domain.Page#isLast()
The following examples show how to use
org.springframework.data.domain.Page#isLast() .
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: 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 2
Source File: AbstractPagerDecorator.java From thymeleaf-spring-data-dialect with Apache License 2.0 | 6 votes |
public final String decorate(final IProcessableElementTag tag, final ITemplateContext context) { String bundleName = getClass().getSimpleName(); Locale locale = context.getLocale(); Page<?> page = PageUtils.findPage(context); // previous String previousPage = PageUtils.createPageUrl(context, page.getNumber() - 1); String prevKey = PageUtils.isFirstPage(page) ? "pager.previous" : "pager.previous.link"; String prev = Messages.getMessage(bundleName, prevKey, locale, previousPage); // next String nextPage = PageUtils.createPageUrl(context, page.getNumber() + 1); String nextKey = page.isLast() ? "pager.next" : "pager.next.link"; String next = Messages.getMessage(bundleName, nextKey, locale, nextPage); String content = Strings.concat(prev, next); return Messages.getMessage(bundleName, "pager", locale, content); }
Example 3
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 4
Source File: TodoServiceImpl.java From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 | 5 votes |
@Override public PagedResponse<Todo> getAllTodos(UserPrincipal currentUser, int page, int size) { validatePageNumberAndSize(page, size); Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, CREATED_AT); Page<Todo> todos = todoRepository.findByCreatedBy(currentUser.getId(), pageable); List<Todo> content = todos.getNumberOfElements() == 0 ? Collections.emptyList() : todos.getContent(); return new PagedResponse<>(content, todos.getNumber(), todos.getSize(), todos.getTotalElements(), todos.getTotalPages(), todos.isLast()); }
Example 5
Source File: AlbumServiceImpl.java From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 | 5 votes |
@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 6
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 7
Source File: PostServiceImpl.java From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 | 5 votes |
@Override public PagedResponse<Post> getPostsByCategory(Long id, int page, int size) { AppUtils.validatePageNumberAndSize(page, size); Category category = categoryRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException(CATEGORY, ID, id)); Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, CREATED_AT); Page<Post> posts = postRepository.findByCategory(category.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 8
Source File: MedicalRepositoryTest.java From Doctor with Apache License 2.0 | 5 votes |
@Test public void test() throws IOException { int page = 0; Sort sort = new Sort(Sort.Direction.ASC, "id"); Page<Medical> medicalPage = medicalRepository.findAll(new PageRequest(page++, 1000,sort)); //写入txt文件 write(medicalPage.getContent(),path1); while (!medicalPage.isLast()) { //再读取一页 medicalPage = medicalRepository.findAll(new PageRequest(page++, 1000)); //写入Tet文件 write(medicalPage.getContent(),path1); } }
Example 9
Source File: PageResponseBodyAdvisor.java From spring-boot-jpa with Apache License 2.0 | 5 votes |
private Optional<String> getHttpHeaderLinksString(ServerHttpRequest request, Page<?> page) { List<String> headerLinks = new ArrayList<>(); if (!page.isFirst()) { headerLinks.add(String.format(LINK_STANDARD_FMT, UriComponentsBuilder.fromHttpRequest(request) .replaceQueryParam(QUERY_PARAM_PAGE, 0) .build(), LINK_HEADER_FIRST)); } if (page.hasPrevious()) { headerLinks.add(String.format(LINK_STANDARD_FMT, UriComponentsBuilder.fromHttpRequest(request) .replaceQueryParam(QUERY_PARAM_PAGE, page.previousPageable().getPageNumber()) .build(), LINK_HEADER_PREVIOUS)); } if (page.hasNext()) { headerLinks.add(String.format(LINK_STANDARD_FMT, UriComponentsBuilder.fromHttpRequest(request) .replaceQueryParam(QUERY_PARAM_PAGE, page.nextPageable().getPageNumber()) .build(), LINK_HEADER_NEXT)); } if (!page.isLast()) { headerLinks.add(String.format(LINK_STANDARD_FMT, UriComponentsBuilder.fromHttpRequest(request) .replaceQueryParam(QUERY_PARAM_PAGE, page.getTotalPages() - 1) .build(), LINK_HEADER_LAST)); } return Optional.of(StringUtils.join(headerLinks, ", ")); }
Example 10
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 11
Source File: FullPaginationDecorator.java From thymeleaf-spring-data-dialect with Apache License 2.0 | 5 votes |
public String decorate(final IProcessableElementTag tag, final ITemplateContext context) { Page<?> page = PageUtils.findPage(context); // laquo String firstPage = PageUtils.createPageUrl(context, 0); Locale locale = context.getLocale(); String laquo = PageUtils.isFirstPage(page) ? getLaquo(locale) : getLaquo(firstPage, locale); // Previous page String previous = getPreviousPageLink(page, context); // Links String pageLinks = createPageLinks(page, context); // Next page String next = getNextPageLink(page, context); // raquo String lastPage = PageUtils.createPageUrl(context, page.getTotalPages() - 1); String raquo = page.isLast() ? getRaquo(locale) : getRaquo(lastPage, locale); boolean isUl = Strings.UL.equalsIgnoreCase(tag.getElementCompleteName()); String currentClass = tag.getAttributeValue(Strings.CLASS); String clas = (isUl && !Strings.isEmpty(currentClass)) ? currentClass : DEFAULT_CLASS; return Messages.getMessage(BUNDLE_NAME, "pagination", locale, clas, laquo, previous, pageLinks, next, raquo); }
Example 12
Source File: CommentServiceImpl.java From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 | 5 votes |
@Override public PagedResponse<Comment> getAllComments(Long postId, int page, int size) { AppUtils.validatePageNumberAndSize(page, size); Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, "createdAt"); Page<Comment> comments = commentRepository.findByPostId(postId, pageable); return new PagedResponse<Comment>(comments.getContent(), comments.getNumber(), comments.getSize(), comments.getTotalElements(), comments.getTotalPages(), comments.isLast()); }
Example 13
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 14
Source File: RelatedContentService.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
/** * Deletes all content related to the given process instance. This includes all field content for a process instance, all * field content on tasks and all related content on tasks. The raw content data will also be removed from content storage * as well as all renditions and rendition data. */ @Transactional public void deleteContentForProcessInstance(String processInstanceId) { int page = 0; Page<RelatedContent> content = contentRepository.findAllContentByProcessInstanceId( processInstanceId, new PageRequest(page, RELATED_CONTENT_INTERNAL_BATCH_SIZE)); final Set<String> storageIds = new HashSet<String>(); // Loop over all content, cascading any referencing entities while (content!= null) { for (RelatedContent relatedContent : content.getContent()) { if (relatedContent.getContentStoreId() != null) { storageIds.add(relatedContent.getContentStoreId()); } } // Get next page, if needed if (!content.isLast()) { page++; content = contentRepository.findAllContentByProcessInstanceId( processInstanceId, new PageRequest(page, RELATED_CONTENT_INTERNAL_BATCH_SIZE)); } else { content = null; } } // Delete raw content AFTER transaction has been committed to prevent missing content on rollback if(!storageIds.isEmpty()) { TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { @Override public void afterCommit() { for(String id : storageIds) { contentStorage.deleteContentObject(id); } } }); } // Batch delete all RelatedContent entities contentRepository.deleteAllContentByProcessInstanceId(processInstanceId); }
Example 15
Source File: TagServiceImpl.java From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 | 3 votes |
@Override public PagedResponse<Tag> getAllTags(int page, int size){ AppUtils.validatePageNumberAndSize(page, size); Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, "createdAt"); Page<Tag> tags = tagRepository.findAll(pageable); List<Tag> content = tags.getNumberOfElements() == 0 ? Collections.emptyList() : tags.getContent(); return new PagedResponse<Tag>(content, tags.getNumber(), tags.getSize(), tags.getTotalElements(), tags.getTotalPages(), tags.isLast()); }
Example 16
Source File: CategoryServiceImpl.java From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 | 3 votes |
@Override public PagedResponse<Category> getAllCategories(int page, int size){ AppUtils.validatePageNumberAndSize(page, size); Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, "createdAt"); Page<Category> categories = categoryRepository.findAll(pageable); List<Category> content = categories.getNumberOfElements() == 0 ? Collections.emptyList() : categories.getContent(); return new PagedResponse<Category>(content, categories.getNumber(), categories.getSize(), categories.getTotalElements(), categories.getTotalPages(), categories.isLast()); }
Example 17
Source File: PostServiceImpl.java From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 | 3 votes |
@Override public PagedResponse<Post> getAllPosts(int page, int size) { validatePageNumberAndSize(page, size); Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, CREATED_AT); Page<Post> posts = postRepository.findAll(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 18
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()); }