Spring querydsl predicate: relationship support

不羁岁月 提交于 2020-01-01 18:54:50

问题


I have a Client entity with an OneToOne relation with Contact. 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

 /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. No error but the @QuerydslPredicate predicate is still null (like if no filters).

Thanks!


回答1:


Found the solution with @QueryInit here: http://www.querydsl.com/static/querydsl/4.0.7/reference/html_single/#d0e2245



来源:https://stackoverflow.com/questions/46927280/spring-querydsl-predicate-relationship-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!