2

I'm currently building a REST API in which I want clients to easily filter on most properties of a specific entity. Using QueryDSL in combination with Spring Data REST (an example by Oliver Gierke) allows me to easily get to 90% of what I want by allowing clients to filter by combining query parameters which refer to properties (e.g. /users?firstName=Dennis&lastName=Laumen). (If you're using the same integration Oliver Gierke's answer to my previous question might also help.)

Unfortunately, when using the additional filters QueryDSL provides, like firstName=Dennis&lastName=Laumen, these do not seem to integrate with the pagination features of Spring Data REST. The pagination links when GETting a collection resource return links which ignore the applied filters (e.g. http://localhost:8080/api/users?page=1&size=20 instead of http://localhost:8080/api/users?page=1&size=20&firstName=Dennis&lastName=Laumen).

Concluding, is it possible to display the correct pagination links when using Spring Data REST and QueryDSL? If so, how?

Community
  • 1
  • 1
Dennis Laumen
  • 3,163
  • 2
  • 21
  • 24

1 Answers1

-1

Yes, my spring data widget repository

extends PagingAndSortingRepository<Widget, String>,QueryDslPredicateExecutor<Widget>,QuerydslBinderCustomizer<QWidget>

and I'm able to use both querydsl and page\size parameters in my http request simulatenously, e.g,

http://localhost:8080/widgets?securityType=XXX&settlementPriceCurrency=ABC&size=16

, and get valid pagination links back:

  "_links" : {
    "first" : {
      "href" : "http://localhost:8080/widgets?page=0&size=16"
    },
    "self" : {
      "href" : "http://localhost:8080/widgets{&sort,projection}",
      "templated" : true
    },
    "next" : {
      "href" : "http://localhost:8080/widgets?page=1&size=16"
    },
    "last" : {
      "href" : "http://localhost:8080/widgets?page=61&size=16"
    },
    "profile" : {
      "href" : "http://localhost:8080/profile/widgets"
    }
  },
  "page" : {
    "size" : 16,
    "totalElements" : 984,
    "totalPages" : 62,
    "number" : 0
  }

using Spring Data Rest 2.6.6.RELEASE and spring data commons 1.13.6

mancini0
  • 4,285
  • 1
  • 29
  • 31
  • This is quite the opposite of what the Op stated. The links generated by Spring Data REST absolutely do NOT have the original query filters (securityType and settlementPriceCurrency). – gregturn Mar 26 '20 at 15:20