当前位置: 首页>>代码示例>>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;未经允许,请勿转载。