如何通过升序对一列进行排序,另一列按Spring Data降序排序?

时间:2020-12-04 15:08:26

Given the following page request let's say I wanted to Sort Descending by "created" but ascending by "name", how would I do that? the api doesn't seem to allow "direction" "field" pairs.

鉴于以下页面请求,假设我想按“已创建”排序降序但按“名称”升序,我该怎么做? api似乎不允许“方向”“场”对。

new PageRequest( 1, 15, Sort.Direction.DESC, "created", "name" )

using Spring Data JPA 1.6.5.

使用Spring Data JPA 1.6.5。

1 个解决方案

#1


Try this

new PageRequest(1, 15, new Sort(
    new Order(Direction.DESC, "created"), 
    new Order(Direction.ASC, "name")
  )

#1


Try this

new PageRequest(1, 15, new Sort(
    new Order(Direction.DESC, "created"), 
    new Order(Direction.ASC, "name")
  )