java - Java Spring 数据:按 ID 描述排序
问题描述
我只希望我的数据按 ID Descendent 排序,但我不知道该怎么做,这是我在服务层中的代码
public Page<Facture> selectByPage(Pageable p) {
Page<Facture> pagedResult = factureRepository.findAll(p);
return pagedResult;
}
解决方案
您可以使用Sort.of(...).descending()
降序按字段排序。
public Page<Facture> selectByPage(Pageable p) {
// Here, replace "id" with your field name that refers to id.
Pageable pSort = PageRequest.of(p.getPageNumber(), p.getPageSize(), Sort.by("id").descending());
Page<Facture> pagedResult = factureRepository.findAll(pSort);
return pagedResult;
}
推荐阅读
- angular - 如何在 Snackbar 中设置消息
- python - 熊猫,转换具有相同日期时间索引值的行
- oracle - Oracle SQL 表在 Create 语句上显示缺少右括号为什么?
- python - 使用 matplotlib python 为决策树分类器绘制 2 个以上的特征
- selenium-chromedriver - 使用 Chrome 驱动程序的 C# Selenium 代理身份验证
- python - 在其他功能中导入模块
- swift - 旋转光照环境内容 ARKit 和 SceneKit
- android - 安装引用库返回数据 utm_source=(not%20set)&utm_medium=(not%20set)?我怎样才能得到网址中提到的确切参数。?
- json - 带有变量的 JSON 对象到 PostgreSQL
- javascript - FlipClock .getTime() 不起作用?不更新返回值