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

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

本文整理了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

  1. private static Direction toDirection(Sort sort, String property) {
  2. if (sort.isUnsorted()) {
  3. return Direction.DESC;
  4. }
  5. Order order = sort.getOrderFor(property);
  6. return order == null ? Direction.DESC : order.isAscending() ? Direction.ASC : Direction.DESC;
  7. }
  8. }

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

  1. private static Direction toDirection(Sort sort, String property) {
  2. if (sort.isUnsorted()) {
  3. return Direction.DESC;
  4. }
  5. Order order = sort.getOrderFor(property);
  6. return order == null ? Direction.DESC : order.isAscending() ? Direction.ASC : Direction.DESC;
  7. }
  8. }

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

  1. /**
  2. * Returns in which direction to sort revisions for the given {@link Sort} instance. Defaults to
  3. * {@link Direction#ASC}.
  4. *
  5. * @param sort must not be {@literal null}.
  6. * @return
  7. */
  8. public static Direction getRevisionDirection(Sort sort) {
  9. Assert.notNull(sort, "Sort must not be null!");
  10. Order order = sort.getOrderFor(PROPERTY);
  11. return order == null ? Direction.ASC : order.getDirection();
  12. }
  13. }

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

  1. @Override
  2. protected Sort processSort(Sort sort) {
  3. if(sort.getOrderFor(DEFAULT_PERIOD_SORT_FIELD) != null){
  4. return sort;
  5. }
  6. return sort.and(new Sort(Direction.ASC, DEFAULT_PERIOD_SORT_FIELD));
  7. }

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

  1. /**
  2. * Creates an url to sort data by fieldName
  3. *
  4. * @param context execution context
  5. * @param fieldName field name to sort
  6. * @return sort URL
  7. */
  8. public static String createSortUrl(final ITemplateContext context, final String fieldName) {
  9. // Params can be prefixed to manage multiple pagination on the same page
  10. final String prefix = getParamPrefix(context);
  11. final Collection<String> excludedParams = Arrays
  12. .asList(new String[] { prefix.concat(SORT), prefix.concat(PAGE) });
  13. final String baseUrl = buildBaseUrl(context, excludedParams);
  14. final StringBuilder sortParam = new StringBuilder();
  15. final Page<?> page = findPage(context);
  16. final Sort sort = page.getSort();
  17. final boolean hasPreviousOrder = sort != null && sort.getOrderFor(fieldName) != null;
  18. if (hasPreviousOrder) {
  19. // Sort parameters exists for this field, modify direction
  20. Order previousOrder = sort.getOrderFor(fieldName);
  21. Direction dir = previousOrder.isAscending() ? Direction.DESC : Direction.ASC;
  22. sortParam.append(fieldName).append(COMMA).append(dir.toString().toLowerCase());
  23. } else {
  24. sortParam.append(fieldName);
  25. }
  26. return buildUrl(baseUrl, context).append(SORT).append(EQ).append(sortParam).toString();
  27. }

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

  1. /**
  2. * Creates an url to sort data by fieldName
  3. *
  4. * @param context execution context
  5. * @param fieldName field name to sort
  6. * @param forcedDir optional, if specified then only this sort direction will be allowed
  7. * @return sort URL
  8. */
  9. public static String createSortUrl(final ITemplateContext context, final String fieldName, final Direction forcedDir) {
  10. // Params can be prefixed to manage multiple pagination on the same page
  11. final String prefix = getParamPrefix(context);
  12. final Collection<String> excludedParams = Arrays
  13. .asList(new String[] { prefix.concat(SORT), prefix.concat(PAGE) });
  14. final String baseUrl = buildBaseUrl(context, excludedParams);
  15. final StringBuilder sortParam = new StringBuilder();
  16. final Page<?> page = findPage(context);
  17. final Sort sort = page.getSort();
  18. final boolean hasPreviousOrder = sort != null && sort.getOrderFor(fieldName) != null;
  19. if (forcedDir != null) {
  20. sortParam.append(fieldName).append(COMMA).append(forcedDir.toString().toLowerCase());
  21. } else if (hasPreviousOrder) {
  22. // Sort parameters exists for this field, modify direction
  23. Order previousOrder = sort.getOrderFor(fieldName);
  24. Direction dir = previousOrder.isAscending() ? Direction.DESC : Direction.ASC;
  25. sortParam.append(fieldName).append(COMMA).append(dir.toString().toLowerCase());
  26. } else {
  27. sortParam.append(fieldName);
  28. }
  29. return buildUrl(baseUrl, context).append(SORT).append(EQ).append(sortParam).toString();
  30. }

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

  1. @SuppressWarnings("unchecked")
  2. private void saveLastSearchParams(final HttpServletRequest request, final String listName, final Pageable pageable, final String search) {
  3. final List<Column> listColumns = SearchFilterUtils.getListColumns(request);
  4. boolean isAsc = true;
  5. int sortColumnPosition = 0;
  6. for (int i = 0; i < listColumns.size(); i++) {
  7. final Order order = pageable.getSort().getOrderFor(listColumns.get(i).getName());
  8. if (order != null) {
  9. isAsc = order.isAscending();
  10. sortColumnPosition = i + 1;
  11. break;
  12. }
  13. }
  14. final String sortDirection = isAsc ? Constants.ASC : Constants.DESC;
  15. final LastSearchParamsDTO backSearch =
  16. new LastSearchParamsDTO(pageable.getPageNumber(), pageable.getPageSize(), search, listName, sortColumnPosition, sortDirection);
  17. Map<String, LastSearchParamsDTO> map = (Map<String, LastSearchParamsDTO>) request.getSession().getAttribute(LAST_SEARCH_PARAMS_MAP);
  18. if (map == null) {
  19. map = new HashMap<String, LastSearchParamsDTO>();
  20. }
  21. map.put(listName, backSearch);
  22. request.getSession().setAttribute(LAST_SEARCH_PARAMS_MAP, map);
  23. }

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

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

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

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

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

  1. protected TypedQuery<T> getQuery(Specification<T> spec, Pageable pageable) {
  2. Sort sort = pageable == null ? null : pageable.getSort();
  3. if (sort != null) {
  4. Field[] fields = getDomainClass().getDeclaredFields();
  5. for (Field field : fields) {
  6. Id id = field.getDeclaredAnnotation(Id.class);
  7. if (id != null) {
  8. Order order = sort.getOrderFor(field.getName());
  9. if (order == null) {
  10. sort = sort.and(new Sort(field.getName()));
  11. }
  12. break;
  13. }
  14. }
  15. }
  16. return getQuery(spec, sort);
  17. }

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

  1. @Override
  2. public Page<StreamDefinition> findAll(Pageable pageable) {
  3. List<StreamDefinition> results;
  4. List<String> allKeys = new ArrayList<>(hashOperations.keys());
  5. int total = allKeys.size();
  6. if (total == 0) {
  7. results = Collections.emptyList();
  8. }
  9. else {
  10. Collections.sort(allKeys, comparatorFor(pageable.getSort().getOrderFor("name").getDirection()));
  11. int start = pageable.getOffset();
  12. int end = Math.min(pageable.getOffset() + pageable.getPageSize(), total);
  13. List<String> pageKeys = allKeys.subList(start, end);
  14. List<String> definitions = hashOperations.multiGet(pageKeys);
  15. results = zipToStreamDefinitions(pageKeys, definitions);
  16. }
  17. return new PageImpl<>(results, pageable, total);
  18. }

相关文章