简体   繁体   English

Spring querydsl谓词:关系支持

[英]Spring querydsl predicate: relationship support

I have a Client entity with an OneToOne relation with Contact. 我有一个与Contact具有OneToOne关系的客户实体。 If I want to get the client name, I need to write: 如果要获取客户端名称,则需要编写:

 client.getContact().getLastName()

I use querydsl lib to filters client list in my spring boot app 我使用querydsl lib过滤我的Spring Boot应用程序中的客户端列表

 /api/clients?contact.lastName=Doe

My controller signature: 我的控制器签名:

 public ResponseEntity<ResponseListDTO> getClients (
        @QuerydslPredicate(root = Client.class) Predicate predicateClient,
        Pageable pageable)

It works well: predicate is well created and filters works. 它运作良好:谓词创建良好,过滤器有效。

But now I need to filter on a field inside two relationship level: 但是现在我需要筛选两个关系级别内的字段:

 client.getContact().getAddress().getCity()

So I wan't to write: 所以我不想写:

 /api/clients?contact.address.city=XXX

But its not mapped with @QuerydslPredicate. 但是它没有映射到@QuerydslPredicate。 No error but the @QuerydslPredicate predicate is still null (like if no filters). 没有错误,但@QuerydslPredicate谓词仍然为null(例如,如果没有过滤器)。

Thanks! 谢谢!

在此处使用@QueryInit找到了解决方案: http : @QueryInit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM