javaapikotlinrequestpageable

How to define direction in request with pageable parameter?


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())
}

Solution

  • 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.