如何在 Spring 数据中对一列进行升序排序,对另一列进行降序排序?
How can I sort one column by ascending and another by descending in Spring Data?
鉴于以下页面请求,假设我想按 "created" 降序排序,但按 "name" 升序排序,我该怎么做? api 似乎不允许 "direction" "field" 对。
new PageRequest( 1, 15, Sort.Direction.DESC, "created", "name" )
使用 Spring 数据 JPA 1.6.5。
试试这个
new PageRequest(1, 15, new Sort(
new Order(Direction.DESC, "created"),
new Order(Direction.ASC, "name")
)
new PageRequest(1, 15, Sort
.by(Sort.Direction.DESC, "created")
.and(Sort.Direction.ASC, "name"))
鉴于以下页面请求,假设我想按 "created" 降序排序,但按 "name" 升序排序,我该怎么做? api 似乎不允许 "direction" "field" 对。
new PageRequest( 1, 15, Sort.Direction.DESC, "created", "name" )
使用 Spring 数据 JPA 1.6.5。
试试这个
new PageRequest(1, 15, new Sort(
new Order(Direction.DESC, "created"),
new Order(Direction.ASC, "name")
)
new PageRequest(1, 15, Sort
.by(Sort.Direction.DESC, "created")
.and(Sort.Direction.ASC, "name"))