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

The following examples show how to use org.springframework.data.domain.Page#hasPrevious() . 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: PageLinksAspect.java    From Showcase with Apache License 2.0 6 votes vote down vote up
@Around("@annotation(org.educama.common.api.resource.PageLinks) && execution(org.springframework.hateoas.ResourceSupport+ *(..)) && args(page, ..)")
public Object pageLinksAdvice(ProceedingJoinPoint joinPoint, Page<?> page) throws Throwable {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
    PageLinks pageLinks = method.getAnnotation(PageLinks.class);
    Class<?> controller = pageLinks.value();
    UriComponentsBuilder original = originalUri(controller, request);
    ResourceSupport resourceSupport = (ResourceSupport) joinPoint.proceed();
    if (page.hasNext()) {
        UriComponentsBuilder nextBuilder = replacePageParams(original, page.nextPageable());
        resourceSupport.add(new Link(nextBuilder.toUriString()).withRel("next"));
    }
    if (page.hasPrevious()) {
        UriComponentsBuilder prevBuilder = replacePageParams(original, page.previousPageable());
        resourceSupport.add(new Link(prevBuilder.toUriString()).withRel("prev"));
    }
    return resourceSupport;
}
 
Example 2
Source File: SongResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@GET
@Produces("application/json")
@Path("/all")
public String all() {
    Pageable wholePage = Pageable.unpaged();
    Page<Song> page = songRepository.findAll(wholePage);
    return page.hasPrevious() + " - " + page.hasNext() + " / " + page.getNumberOfElements();
}
 
Example 3
Source File: SongResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@GET
@Produces("application/json")
@Path("/page/{num}/{size}")
public String songs(@PathParam("num") int pageNum, @PathParam("size") int pageSize) {
    PageRequest pageRequest = PageRequest.of(pageNum, pageSize);
    Page<Song> page = songRepository.findAll(pageRequest);
    return page.hasPrevious() + " - " + page.hasNext() + " / " + page.getNumberOfElements();
}
 
Example 4
Source File: PageResponseBodyAdvisor.java    From spring-boot-jpa with Apache License 2.0 5 votes vote down vote up
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 5
Source File: PersonResource.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@GET
@Path("/name/joinedOrder/{name}/page/{size}/{num}")
public String byNamePage(@PathParam("name") String name, @PathParam("size") int pageSize, @PathParam("num") int pageNum) {
    Page<Person> page = personRepository.findByNameOrderByJoined(name, PageRequest.of(pageNum, pageSize));
    return page.hasPrevious() + " - " + page.hasNext() + " / " + page.getNumberOfElements();
}
 
Example 6
Source File: PageUtils.java    From thymeleaf-spring-data-dialect with Apache License 2.0 4 votes vote down vote up
public static boolean hasPrevious(Page<?> page) {
		return page.getTotalPages()>0 && page.hasPrevious();
}