In SpringMVC, we can use @SortDefault
or @PageableDefault
to quickly complete the default sorting of Pageable
Most of what we can query is to sort a certain field:
@PageableDefault(sort = {"weight"}, direction = Sort.Direction.DESC)
Pageable pageable
@SortDefault(sort = {"weight"}, direction = Sort.Direction.ASC) Pageable pageable
Or sort certain fields, but the sorting rules are the same (for example, all are in ascending order):
@SortDefault(sort = {"weight", "createTime"}, direction = Sort.Direction.ASC) Pageable pageable
If we want to set multiple sort fields, and the sorting method of each sort field is not consistent, we can use the following code:
public Page<Notice> page(@SortDefault.SortDefaults({
@SortDefault(sort = {"weight"}, direction = Sort.Direction.ASC),
@SortDefault(sort = {"createTime"}, direction = Sort.Direction.DESC)})
Pageable pageable) {
At this point, the above code will be weight
in ascending order by 061b15c2346dad, and then sorted in reverse order by createTime.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。