英文:
How to define direction in request with pageable parameter?
问题
我有一个查询,它以可分页的方式作为参数。我将方向定义为DESC,但这没有任何效果。这是我的请求。您能否帮助我以一种使结果以降序排序返回的方式来构建这些请求?
我已经在下面的图片中发布了我的请求。它能工作,但不能对结果进行排序。
谢谢
这是控制器代码:
@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())
}
英文:
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
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())
}
答案1
得分: 4
你需要发送排序字段,以便按降序进行排序。(参考链接)示例:
http://localhost:8080/people?sort=id,desc
这里的 id
是排序字段,desc
是以逗号分隔的排序方向。
因此,在 PostMan 中,您需要在 sort
参数中发送 id,desc
,以按照 id
降序排序。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论