2

I have a query that takes pageable as a parameter. I define the direction as DESC but this takes no effect. This is my request. Could you please help me formulate the requests in a way that the results come back sorted in descending order? I have posted my request in the picture below. It works but it does not sort the results

Thank you enter image description here

This is the controller code:

@GetMapping
fun listMessages(@RequestParam conversationRef: String,
                 @RequestParam fromDate: Instant, @RequestParam toDate: Instant, 
                 pageable: Pageable): PaginatedCollection<MessageVO> {
                     return messageService.listAll(fromDate, toDate, pageable, 
                              conversationRef).data ?: PaginatedCollection(listOf(), 
                              PaginationVO.build(), SortVO.build())
}
C96
  • 477
  • 8
  • 33

1 Answers1

4

You need to send sort field for which you want to sort by descending.(Ref) Ex:

http://localhost:8080/people?sort=id,desc

Here id is sort field and desc is sort direction separated by a comma.

So, you need to send id,desc on sort param in PostMan for sort by id in desecending order.

Eklavya
  • 17,618
  • 4
  • 28
  • 57
  • if you want multiple soring then you can add like: http://localhost:8080/people?sort=id,desc&sort=name,desc&time,asc NOTE that default is asc – destan Aug 09 '23 at 05:59