当前位置: 首页>>代码示例>>Java>>正文


Java PageRequest.of方法代码示例

本文整理汇总了Java中org.springframework.data.domain.PageRequest.of方法的典型用法代码示例。如果您正苦于以下问题:Java PageRequest.of方法的具体用法?Java PageRequest.of怎么用?Java PageRequest.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.data.domain.PageRequest的用法示例。


在下文中一共展示了PageRequest.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveAndBroadcast

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
public void saveAndBroadcast(InboundSmsMessage smsMessage){
    log.info("Inbound message received {}", smsMessage);
    
    inboundSmsMessageRepository.save(smsMessage);
    
    Pageable page = (Pageable) PageRequest.of(0, 1, Direction.DESC, "date");
    List<Conversation> conversations = conversationRepository.findByPhoneNumber(smsMessage.getMsisdn(), page);
    
    if( ! conversations.isEmpty()){
        Conversation conversation =  conversations.get(0);
        Optional<Participant> user = conversation.findParticipantByPhone(smsMessage.getMsisdn());
        
        if(user.isPresent()){
            ConversationMessage conversationMessage = createConversationMessage(smsMessage, conversation, user.get());
            broadcastMessage(conversationMessage);
        }else{
            log.warn("No participant found associated with {} in {}", smsMessage.getMsisdn(), conversation.getId());
        }
            
    }else{
        log.warn("No conversation found associated with {}", smsMessage.getMsisdn());
    }
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:24,代码来源:SmsConversationService.java

示例2: toPageable

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
/**
 * Decodes a continuation-token into a pageable
 * @param token The token with the page information
 * @param sort The sort to use
 */
public static Pageable toPageable(ContinuationToken token, Sort sort){

    if(token == null) throw new ArgumentNullException("token");
    if(sort == null) throw new ArgumentNullException("sort");

    String[] parts = token.getToken().split("-");
    if(parts.length == 2){
        try {
            int page = Integer.parseInt(parts[0]);
            int size = Integer.parseInt(parts[1]);
            return PageRequest.of(page, size, sort);
        }catch (NumberFormatException e){
            throw new IllegalArgumentException("The given token was not in a valid page-size format: " + token, e);
        }
    }else{
        throw new IllegalArgumentException("The given token was not in a valid page-size format: " + token);
    }
}
 
开发者ID:ElderByte-,项目名称:spring-cloud-starter-bootstrap,代码行数:24,代码来源:ContinuationSupport.java

示例3: fromPage

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
@Test
public void fromPage(){

    // Given: A Page

    Page<String> myPage = new PageImpl<>(
            Arrays.asList("a", "b", "c"),
            PageRequest.of(1, 3), // page == 1 => 2nd page (zero index)
            9
    );


    ContinuableListing<String> listing = ContinuationSupport.fromPage(myPage);


    Assert.assertEquals(3, listing.getChunkSize());
    Assert.assertEquals(3, listing.getContent().size());
    Assert.assertEquals(true, listing.hasMore());
    Assert.assertEquals("1-3", listing.getContinuationToken());
    Assert.assertEquals("2-3", listing.getNextContinuationToken());
}
 
开发者ID:ElderByte-,项目名称:spring-cloud-starter-bootstrap,代码行数:22,代码来源:ContinuationSupportTest.java

示例4: testDefaultRepository

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
@Test
public void testDefaultRepository() {
    Assert.assertNotNull(getRepository());

    List<SmokeEntity> all = TestUtils.toList(getRepository().findAll());
    Assert.assertEquals(4L, all.size());

    Assert.assertEquals(4L, getRepository().count());

    Iterable<SmokeEntity> sorted = getRepository().findAll(Sort.by(Sort.Direction.DESC, "name"));
    Assert.assertEquals("4", sorted.iterator().next().getId());

    Pageable pageable = PageRequest.of(1, 2, Sort.by(Sort.Order.by("type")));
    Page<SmokeEntity> pageables = getRepository().findAll(pageable);
    Assert.assertEquals(2, pageables.getNumberOfElements());
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:17,代码来源:SmokeTestBase.java

示例5: newSortedPageRequest

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
/**
 * Build and return a new {@link PageRequest} from the page information and ordering.
 * 
 * @param ormMapping
 *            The mapping from JSon name to ORM property or function.
 * @param parameters
 *            The available query parameters.
 * @param pageLength
 *            The resolved page length.
 * @param firstPage
 *            The page index.
 * @param column
 *            The sorted column name.
 * @param caseSensitiveColumns
 *            Optional JSon columns name where the case sensitive ordering is requested. The "lower" function will
 *            not be
 *            used for the "ORDER BY" in this case.
 * @return The new {@link PageRequest} with pagination and order.
 */
@NotNull
private PageRequest newSortedPageRequest(final Map<String, String> ormMapping, final MultivaluedMap<String, String> parameters,
		final int pageLength, final int firstPage, final String column, final Collection<String> caseSensitiveColumns) {
	final String direction = getSortDirection(parameters);
	final PageRequest pageRequest;
	final String ormProperty = getOrmColumn(ormMapping, column);
	if (ormProperty == null) {
		// Not enough information for build an ORDER BY
		pageRequest = PageRequest.of(firstPage, pageLength);
	} else {
		// Ordering query can be built
		final Sort sort;
		if ((caseSensitiveColumns == null || !caseSensitiveColumns.contains(column)) && ormProperty.indexOf('(') == -1) {
			if (ormProperty.indexOf('.') == -1) {
				sort = Sort.by(new Sort.Order(Direction.valueOf(direction.toUpperCase(Locale.ENGLISH)), ormProperty).ignoreCase());
			} else {
				sort = JpaSort.unsafe(Direction.valueOf(direction.toUpperCase(Locale.ENGLISH)), "UPPER(" + ormProperty + ")");
			}
		} else {
			sort = JpaSort.unsafe(Direction.valueOf(direction.toUpperCase(Locale.ENGLISH)), ormProperty);
		}
		pageRequest = PageRequest.of(firstPage, pageLength, sort);
	}
	return pageRequest;
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:45,代码来源:PaginationJson.java

示例6: getAllBooks

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
@GetMapping
public ResponseEntity<List<Book>> getAllBooks(
        @PageableDefault(size = MAX_PAGE_SIZE) Pageable pageable,
        @RequestParam(required = false, defaultValue = "id") String sort,
        @RequestParam(required = false, defaultValue = "asc") String order) {
    final PageRequest pr = PageRequest.of(
            pageable.getPageNumber(), pageable.getPageSize(),
            Sort.by("asc" .equals(order) ? Sort.Direction.ASC : Sort.Direction.DESC, sort)
    );

    Page<Book> booksPage = bookRepository.findAll(pr);

    if (booksPage.getContent().isEmpty()) {
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    } else {
        long totalBooks = booksPage.getTotalElements();
        int nbPageBooks = booksPage.getNumberOfElements();

        HttpHeaders headers = new HttpHeaders();
        headers.add("X-Total-Count", String.valueOf(totalBooks));

        if (nbPageBooks < totalBooks) {
            headers.add("first", buildPageUri(PageRequest.of(0, booksPage.getSize())));
            headers.add("last", buildPageUri(PageRequest.of(booksPage.getTotalPages() - 1, booksPage.getSize())));

            if (booksPage.hasNext()) {
                headers.add("next", buildPageUri(booksPage.nextPageable()));
            }

            if (booksPage.hasPrevious()) {
                headers.add("prev", buildPageUri(booksPage.previousPageable()));
            }

            return new ResponseEntity<>(booksPage.getContent(), headers, HttpStatus.PARTIAL_CONTENT);
        } else {
            return new ResponseEntity(booksPage.getContent(), headers, HttpStatus.OK);
        }
    }
}
 
开发者ID:sbouclier,项目名称:java-rest-books,代码行数:40,代码来源:BookController.java

示例7: pagedResult

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
/**
 * Apply pagination criteria.
 */
private <T> Page<T> pagedResult(final Class<T> entityType, final UiPageRequest uiPageRequest, final CriteriaQuery<T> query,
		final Specification<T> spec) {
	final TypedQuery<T> query2 = em.createQuery(query);
	if (uiPageRequest.getPage() > 0 && uiPageRequest.getPageSize() > 0 || uiPageRequest.getUiSort() != null) {
		// Build the main query
		final Pageable pageable = PageRequest.of(Math.max(0, uiPageRequest.getPage() - 1), Math.max(1, uiPageRequest.getPageSize()));
		return readPage(entityType, query2, pageable, spec);
	}

	// Build the main query
	return new PageImpl<>(query2.getResultList());
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:16,代码来源:PaginationDao.java

示例8: showPage

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
@GetMapping("/conversations")
public String showPage(ModelMap model){
    PageRequest req = PageRequest.of(0, 30, Direction.DESC, "date");
    model.put("conversations", repository.findAll(req));
    return "conversations";
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:7,代码来源:AdminConversationsController.java

示例9: getMessages

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
public List<ConversationMessage> getMessages(Conversation conversation, Instant createdBefore){
    Pageable pageable = PageRequest.of(0, 30, Direction.ASC, "created");
    Page<ConversationMessage> page = repository.findByConversationAndCreatedBefore(conversation, createdBefore, pageable);
    page.getContent().forEach( msg -> msg.setConversation(conversation));
    return page.getContent();
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:7,代码来源:AdminConversationService.java

示例10: getConversations

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
@SubscribeMapping("/conversations")
public List<Conversation> getConversations(){
    PageRequest req = PageRequest.of(0, 30, Direction.DESC, "date");
    return conversationRepository.findAll(req).getContent();
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:6,代码来源:ConversationController.java

示例11: getLastMessages

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
public List<ConversationMessage> getLastMessages(Conversation conversation){
    Pageable pageable = PageRequest.of(0, 15, Direction.DESC, "created");
    Page<ConversationMessage> page = conversationMessageRepository.findByConversation(conversation, pageable);
    page.getContent().forEach( msg -> msg.setConversation(conversation));
    return page.getContent();
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:7,代码来源:ConversationService.java

示例12: getMessages

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
public List<ConversationMessage> getMessages(Conversation conversation, Instant createdBefore){
    Pageable pageable = PageRequest.of(0, 15, Direction.ASC, "created");
    Page<ConversationMessage> page = conversationMessageRepository.findByConversationAndCreatedBefore(conversation, createdBefore, pageable);
    page.getContent().forEach( msg -> msg.setConversation(conversation));
    return page.getContent();
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:7,代码来源:ConversationService.java

示例13: findSortedBy

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
private List<Trip> findSortedBy(String property){
    Sort sort = Sort.by(Direction.DESC, property);
    PageRequest request = PageRequest.of(0,  HOMEPAGE_COLUMN_LENGHT, sort);
    Page<Trip> page = tripRepository.findAll(request);
    if (log.isDebugEnabled()) log.debug("Result for {} page: {} ", property, page );
    return page.getContent();
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:8,代码来源:HomePageHelper.java

示例14: getPageRequest

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
/**
 * Get DataTable pagination information from query parameters.
 * 
 * @param uriInfo
 *            Query parameters.
 * @param ormMapping
 *            Optional JSon to ORM property mapping.
 * @param caseSensitiveColumns
 *            Optional JSon columns name where the case sensitive ordering is requested. The "lower" function will
 *            not be
 *            used for the "ORDER BY" in this case.
 * @return a {@link PageRequest} instance containing sort and page sizes.
 */
public PageRequest getPageRequest(final UriInfo uriInfo, final Map<String, String> ormMapping, final Collection<String> caseSensitiveColumns) {
	// Update pagination informations
	if (uriInfo == null) {
		return PageRequest.of(0, 10);
	}
	final MultivaluedMap<String, String> parameters = uriInfo.getQueryParameters();
	final int pageLength = getPageLength(parameters);
	final int firstPage = Optional.ofNullable(getPage(parameters)).map(p -> p - 1).orElse(getStart(parameters) / pageLength);

	// Update sort informations
	return buildOrderedPageRequest(ormMapping, parameters, pageLength, firstPage, caseSensitiveColumns);
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:26,代码来源:PaginationJson.java

示例15: applyPagination

import org.springframework.data.domain.PageRequest; //导入方法依赖的package包/类
/**
 * @param uriInfo
 *            filter data.
 * @param items
 *            the items to paginate in memory.
 * @param transformer
 *            the paginated item transformer.
 * @return the paginated items with pagination information.
 */
public <E, T> TableItem<T> applyPagination(final UriInfo uriInfo, final Collection<E> items, final Function<E, T> transformer) {
	final UiPageRequest uiPageRequest = paginationJson.getUiPageRequest(uriInfo);
	final PageRequest pageRequest = PageRequest.of(uiPageRequest.getPage() - 1, uiPageRequest.getPageSize());
	return paginationJson.applyPagination(uriInfo, newPage(items, pageRequest), transformer);
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:15,代码来源:InMemoryPagination.java


注:本文中的org.springframework.data.domain.PageRequest.of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。