Spring Data dynamic query

后端 未结 2 927
-上瘾入骨i
-上瘾入骨i 2021-02-20 07:05

I\'m trying to set up a dynamic query using spring data, basically I have an array with a bunch of characteristics and I need to assemble the query based on those characteristic

相关标签:
2条回答
  • 2021-02-20 07:47

    Use Spring Data JPA Querydsl. Read it here

    0 讨论(0)
  • 2021-02-20 08:05

    Yes. @Query supports pageable.. and yes there's another way to accomplish this.

    You could take a look at building query with criteria, that allow you add AND / OR where conditions dynamically. I actually use querydsl to facilitate my development.

    In this post you can find a good explanation of both: http://spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/

    Altough it could be seem more complex at beginning, the use of this feature will make your code more consistent with increasing complexity

    0 讨论(0)
提交回复
热议问题