org.springframework.data.domain.Sort.getOrderFor()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(200)

本文整理了Java中org.springframework.data.domain.Sort.getOrderFor()方法的一些代码示例,展示了Sort.getOrderFor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sort.getOrderFor()方法的具体详情如下:
包路径:org.springframework.data.domain.Sort
类名称:Sort
方法名:getOrderFor

Sort.getOrderFor介绍

[英]Returns the order registered for the given property.
[中]返回为给定属性注册的顺序。

代码示例

代码示例来源:origin: spring-projects/spring-data-mongodb

private static Direction toDirection(Sort sort, String property) {

    if (sort.isUnsorted()) {
      return Direction.DESC;
    }

    Order order = sort.getOrderFor(property);
    return order == null ? Direction.DESC : order.isAscending() ? Direction.ASC : Direction.DESC;
  }
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

private static Direction toDirection(Sort sort, String property) {

    if (sort.isUnsorted()) {
      return Direction.DESC;
    }

    Order order = sort.getOrderFor(property);
    return order == null ? Direction.DESC : order.isAscending() ? Direction.ASC : Direction.DESC;
  }
}

代码示例来源:origin: apache/servicemix-bundles

/**
   * Returns in which direction to sort revisions for the given {@link Sort} instance. Defaults to
   * {@link Direction#ASC}.
   *
   * @param sort must not be {@literal null}.
   * @return
   */
  public static Direction getRevisionDirection(Sort sort) {

    Assert.notNull(sort, "Sort must not be null!");

    Order order = sort.getOrderFor(PROPERTY);
    return order == null ? Direction.ASC : order.getDirection();
  }
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

@Override
protected Sort processSort(Sort sort) {
  if(sort.getOrderFor(DEFAULT_PERIOD_SORT_FIELD) != null){
    return sort;
  }
  return sort.and(new Sort(Direction.ASC, DEFAULT_PERIOD_SORT_FIELD));
}

代码示例来源:origin: io.github.jpenren/thymeleaf-spring-data-dialect

/**
 * Creates an url to sort data by fieldName
 * 
 * @param context execution context
 * @param fieldName field name to sort
 * @return sort URL
 */
public static String createSortUrl(final ITemplateContext context, final String fieldName) {
  // Params can be prefixed to manage multiple pagination on the same page
  final String prefix = getParamPrefix(context);
  final Collection<String> excludedParams = Arrays
      .asList(new String[] { prefix.concat(SORT), prefix.concat(PAGE) });
  final String baseUrl = buildBaseUrl(context, excludedParams);
  final StringBuilder sortParam = new StringBuilder();
  final Page<?> page = findPage(context);
  final Sort sort = page.getSort();
  final boolean hasPreviousOrder = sort != null && sort.getOrderFor(fieldName) != null;
  if (hasPreviousOrder) {
    // Sort parameters exists for this field, modify direction
    Order previousOrder = sort.getOrderFor(fieldName);
    Direction dir = previousOrder.isAscending() ? Direction.DESC : Direction.ASC;
    sortParam.append(fieldName).append(COMMA).append(dir.toString().toLowerCase());
  } else {
    sortParam.append(fieldName);
  }
  return buildUrl(baseUrl, context).append(SORT).append(EQ).append(sortParam).toString();
}

代码示例来源:origin: jpenren/thymeleaf-spring-data-dialect

/**
 * Creates an url to sort data by fieldName
 * 
 * @param context execution context
 * @param fieldName field name to sort
 * @param forcedDir optional, if specified then only this sort direction will be allowed
 * @return sort URL
 */
public static String createSortUrl(final ITemplateContext context, final String fieldName, final Direction forcedDir) {
  // Params can be prefixed to manage multiple pagination on the same page
  final String prefix = getParamPrefix(context);
  final Collection<String> excludedParams = Arrays
      .asList(new String[] { prefix.concat(SORT), prefix.concat(PAGE) });
  final String baseUrl = buildBaseUrl(context, excludedParams);
  final StringBuilder sortParam = new StringBuilder();
  final Page<?> page = findPage(context);
  final Sort sort = page.getSort();
  final boolean hasPreviousOrder = sort != null && sort.getOrderFor(fieldName) != null;
  if (forcedDir != null) {
    sortParam.append(fieldName).append(COMMA).append(forcedDir.toString().toLowerCase());
  } else if (hasPreviousOrder) {
    // Sort parameters exists for this field, modify direction
    Order previousOrder = sort.getOrderFor(fieldName);
    Direction dir = previousOrder.isAscending() ? Direction.DESC : Direction.ASC;
    sortParam.append(fieldName).append(COMMA).append(dir.toString().toLowerCase());
  } else {
    sortParam.append(fieldName);
  }
  return buildUrl(baseUrl, context).append(SORT).append(EQ).append(sortParam).toString();
}

代码示例来源:origin: sentilo/sentilo

@SuppressWarnings("unchecked")
private void saveLastSearchParams(final HttpServletRequest request, final String listName, final Pageable pageable, final String search) {
 final List<Column> listColumns = SearchFilterUtils.getListColumns(request);
 boolean isAsc = true;
 int sortColumnPosition = 0;
 for (int i = 0; i < listColumns.size(); i++) {
  final Order order = pageable.getSort().getOrderFor(listColumns.get(i).getName());
  if (order != null) {
   isAsc = order.isAscending();
   sortColumnPosition = i + 1;
   break;
  }
 }
 final String sortDirection = isAsc ? Constants.ASC : Constants.DESC;
 final LastSearchParamsDTO backSearch =
   new LastSearchParamsDTO(pageable.getPageNumber(), pageable.getPageSize(), search, listName, sortColumnPosition, sortDirection);
 Map<String, LastSearchParamsDTO> map = (Map<String, LastSearchParamsDTO>) request.getSession().getAttribute(LAST_SEARCH_PARAMS_MAP);
 if (map == null) {
  map = new HashMap<String, LastSearchParamsDTO>();
 }
 map.put(listName, backSearch);
 request.getSession().setAttribute(LAST_SEARCH_PARAMS_MAP, map);
}

代码示例来源:origin: io.github.jpenren/thymeleaf-spring-data-dialect

@Override
protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName,
    String attributeValue, IElementTagStructureHandler structureHandler) {
  String attrValue = String.valueOf(Expressions.evaluate(context, attributeValue)).trim();
  Page<?> page = PageUtils.findPage(context);
  String url = PageUtils.createSortUrl(context, attrValue);
  // Append class to the element if sorted by this field
  Sort sort = page.getSort();
  boolean isSorted = sort != null && sort.getOrderFor(attributeValue) != null;
  String clas = isSorted
      ? SORTED_PREFIX.concat(sort.getOrderFor(attributeValue).getDirection().toString().toLowerCase())
      : EMPTY;
  structureHandler.setAttribute(HREF, url);
  String currentClass = tag.getAttributeValue(CLASS);
  structureHandler.setAttribute(CLASS, Strings.concat(currentClass, BLANK, clas));
}

代码示例来源:origin: jpenren/thymeleaf-spring-data-dialect

@Override
protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName,
    String attributeValue, IElementTagStructureHandler structureHandler) {
  String attrValue = String.valueOf(Expressions.evaluate(context, attributeValue)).trim();
  Page<?> page = PageUtils.findPage(context);
  String url = PageUtils.createSortUrl(context, attrValue, getForcedDirection());
  // Append class to the element if sorted by this field
  Sort sort = page.getSort();
  boolean isSorted = sort != null && sort.getOrderFor(attrValue) != null;
  String clas = isSorted
      ? SORTED_PREFIX.concat(sort.getOrderFor(attrValue).getDirection().toString().toLowerCase())
      : EMPTY;
  structureHandler.setAttribute(HREF, url);
  String currentClass = tag.getAttributeValue(CLASS);
  structureHandler.setAttribute(CLASS, Strings.concat(currentClass, BLANK, clas));
}

代码示例来源:origin: top.wboost/common-web

protected TypedQuery<T> getQuery(Specification<T> spec, Pageable pageable) {
  Sort sort = pageable == null ? null : pageable.getSort();
  if (sort != null) {
    Field[] fields = getDomainClass().getDeclaredFields();
    for (Field field : fields) {
      Id id = field.getDeclaredAnnotation(Id.class);
      if (id != null) {
        Order order = sort.getOrderFor(field.getName());
        if (order == null) {
          sort = sort.and(new Sort(field.getName()));
        }
        break;
      }
    }
  }
  return getQuery(spec, sort);
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-dataflow-admin-starter

@Override
public Page<StreamDefinition> findAll(Pageable pageable) {
  List<StreamDefinition> results;
  List<String> allKeys = new ArrayList<>(hashOperations.keys());
  int total = allKeys.size();
  if (total == 0) {
    results = Collections.emptyList();
  }
  else {
    Collections.sort(allKeys, comparatorFor(pageable.getSort().getOrderFor("name").getDirection()));
    int start = pageable.getOffset();
    int end = Math.min(pageable.getOffset() + pageable.getPageSize(), total);
    List<String> pageKeys = allKeys.subList(start, end);
    List<String> definitions = hashOperations.multiGet(pageKeys);
    results = zipToStreamDefinitions(pageKeys, definitions);
  }
  return new PageImpl<>(results, pageable, total);
}

相关文章