Spring Data QuerydslBinderCustomizer MongoDb List查询

时间:2016-04-25 15:53:49

标签: mongodb binding spring-data querydsl

我有2个文件映射到MongoDb

    @Document
    public class Blog {
        @Id
        private String id;
        private String name;
        private List<Article> articles = new ArrayList<>();
....

    @Document
    public class Article {
        @Id
        private String id;
        private String name;
        private String author;
...

我正在使用QuerydslBinderCustomizer进行绑定。当我绑定例如String.class时,一切都完美无缺:

/blogs?name=blog_name&id=3409845jk45


public interface BlogRepository extends MongoRepository<Blog, String>
        , QueryDslPredicateExecutor<Blog>, QuerydslBinderCustomizer<QBlog> {

    @Override
    default public void customize(QuerydslBindings bindings, QBlog root) {

        bindings.bind(String.class)
            .first((StringPath path, String value) -> {
                return path.eq(value);
             });
    }
}

但我不知道如何绑定这样的东西:

/blogs?name=blog_name&articles.name=nice_article

在Mongo中查询类似的内容:

Predicate filterBlog = qBlog.name.eq(parameters.getFirst("name"))
                .and(qBlog.articles.any().author.eq(parameters.getFirst("articles.name")));

return (List<Blog>) blogRepository.findAll(filterBlog );

0 个答案:

没有答案