本文整理汇总了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();
}