【问题标题】:Sorting with spring and querydsl使用 spring 和 querydsl 排序
【发布时间】:2018-07-10 00:18:21
【问题描述】:

我正在尝试在 @RepositoryRestResource 中进行排序,我正在创建一个自定义查询几个 querydsl 接口,但我似乎遗漏了一些东西。分页有效,但您无法对包含多个单词(shippedQty)的字段进行排序。在其他字段上排序工作正常。这是 PagingAndSortingRepository 错误还是我必须做其他事情或多字字段?

@RepositoryRestResource(path = "/report", collectionResourceRel = "report", itemResourceRel = "report")
public interface ReportRepository extends PagingAndSortingRepository<Report, Long>, QueryDslPredicateExecutor<Report>,
        QuerydslBinderCustomizer<QReport> {

    @Override
    default void customize(QuerydslBindings bindings, QReport report) {
        bindings.including(
                report.description,
                report.item,
                report.program,
                report.shippedQty,
        );
        bindings.excludeUnlistedProperties(true);

        SingleValueBinding<NumberPath<Integer>, Integer> numberPathContains = (path, value) -> path.stringValue().contains(value.toString());

        bindings.bind(firstFill.description).first(StringPath::containsIgnoreCase);
        bindings.bind(firstFill.item).first(StringPath::containsIgnoreCase);
        bindings.bind(firstFill.program).first(StringPath::containsIgnoreCase);
        bindings.bind(firstFill.shippedQty).as("shipped_qty").first(numberPathContains);

 }
}

这排序正确:

http://localhost:8080/api/v1/report?page=0&size=5&sort=description,asc

这不是:

http://localhost:8080/api/v1/report?page=0&size=5&sort=shipped_qty,asc

【问题讨论】:

    标签: spring-boot querydsl


    【解决方案1】:

    我自己也遇到了这个问题。事实证明,Sort 不使用 QueryDSL 存储库绑定别名,而是使用“Q”实体路径的名称。

    【讨论】:

      猜你喜欢
      • 2015-02-14
      • 2016-10-21
      • 2014-05-11
      • 2012-11-09
      • 2012-10-15
      • 1970-01-01
      • 2017-09-02
      • 2016-12-13
      • 2014-08-01
      相关资源
      最近更新 更多