如何在带有分页参数的请求中定义方向?

huangapple go评论73阅读模式
英文:

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

Thank you
如何在带有分页参数的请求中定义方向?

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.

huangapple
  • 本文由 发表于 2020年8月20日 20:25:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63505076.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定