【问题标题】:Filter nested collection not working as expected with Querydsl, Spring Data REST使用 Querydsl、Spring Data REST 过滤嵌套集合无法按预期工作
【发布时间】:2017-10-12 07:58:58
【问题描述】:

基于StoreRepository@Oliver Gierke

如果Store 有一个products 的集合

/api/store?products.name=Sony%20Vaio

Returns Stores that have Sony Viao on its products 好,但所有产品都退回, 我只需要名称为 Sony Viao 的产品。

public interface StoreRepository extends PagingAndSortingRepository<Store, String>, 
    QueryDslPredicateExecutor<Store>, QuerydslBinderCustomizer<QStore> {

    default void customize(QuerydslBindings bindings, QStore store) {
        bindings.bind(store.products.any().first((path, value) -> path.equals(value));
    }
}

任何帮助将不胜感激!

【问题讨论】:

  • 您真的需要自定义QueryDSL 绑定吗?没有customize 方法,您的代码对我有用。可通过on Github 审核示例项目。

标签: spring-data-jpa spring-data-rest querydsl


【解决方案1】:

我认为问题在于您没有在产品中指定属性名称。试试这个:

bindings.bind(store.products.any().name).first((path, value) -> path.eq(value));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-05
    • 1970-01-01
    相关资源
    最近更新 更多