Spring MVC @SortDefault multi-field sorting
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.
河北工业大学梦云智软件开发团队
河北工业大学梦云智软件开发团队
2.6k 声望
203 粉丝
推荐阅读
统一为gitlab runner 设置 npm 仓库地址
由于众所周知的原因,npm在执行install 或 ci时请求官方仓库会相当慢,为此我们可以在gitlab的全局中设置以下环境变量来为npm指定国内的阿里云仓库。方法如下:
myskies阅读 237
Spring Boot 3.0横空出世,快来看看是不是该升级了
Spring boot 3.0于2022年11月正式发布了,这次的发布对于我们普通程序员的影响有多少呢?我们是不是需要考虑立马升级到Spring Boot3.0呢?
flydean阅读 576
SpringMVC使用MultipartFile对象实现文件上传
1、添加依赖 {代码...} 2、在SpringMVC的配置文件中添加配置: {代码...} 3、控制器方法: {代码...}
辉辉阅读 352
SpringMVC--(使用ResponseEntity)实现下载功能
{代码...}
辉辉阅读 352
吹爆Alibaba自研的Spring全能笔记,建议人手一份!
Spring 这个技术栈,想必大家都知道,这玩意面试必考工作必用,对于每位 Java 程序员来说都是至关重要的;俗话说 Java 开发不学习 Spring 就像士兵上战场不带枪,我认为这个比喻很形象。Spring 几乎占据了 Java w...
Java架构师阅读 244
Spring MVC执行流程及源码详解
Spring MVC中各组件初始化过程已在上篇分享:初始化过程一、SpringMVC常用组件DispatcherServlet:前端控制器,统一处理请求和响应,整个流程控制的中心,由它调用其它组件处理用户的请求HandlerMapping:处理器映...
Dream_sky阅读 126
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。