當前位置: 首頁>>代碼示例>>Java>>正文


Java Sort.by方法代碼示例

本文整理匯總了Java中org.springframework.data.domain.Sort.by方法的典型用法代碼示例。如果您正苦於以下問題:Java Sort.by方法的具體用法?Java Sort.by怎麽用?Java Sort.by使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.data.domain.Sort的用法示例。


在下文中一共展示了Sort.by方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: newSortedPageRequest

import org.springframework.data.domain.Sort; //導入方法依賴的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

示例2: findSortedBy

import org.springframework.data.domain.Sort; //導入方法依賴的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


注:本文中的org.springframework.data.domain.Sort.by方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。