本文整理匯總了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;
}
示例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();
}