如何在 Spring 数据中使用排序 GET 方法
How to Use sorting in Spring Data Rest GET method
当我在 spring 框架中创建任何存储库时,它会默认提供使用此 API
获取实体所有记录的方法
获取:http://localhost:3000/api/addresses
它按升序发送数据,但是如果我希望我的数据按降序排列,我该如何指定呢?
地址存储库
public interface AddressRepository extends JpaRepository<Address, Long>
{
}
在 AddressRepository 中尝试 class 类似于:
public List<Address> findAllByOrderByIdDesc();
当然,您可以将 "ById" 部分更改为要用于排序的任何其他字段。
您也可以将其指定为请求的一部分,请查看此处的文档 Sorting。
也请看看类似的回答。
也许,你可以:
localhost:3000/api/addresses?sort={property},desc
这将帮助您按 属性 desc
排序
当我在 spring 框架中创建任何存储库时,它会默认提供使用此 API
获取实体所有记录的方法获取:http://localhost:3000/api/addresses
它按升序发送数据,但是如果我希望我的数据按降序排列,我该如何指定呢?
地址存储库
public interface AddressRepository extends JpaRepository<Address, Long>
{
}
在 AddressRepository 中尝试 class 类似于:
public List<Address> findAllByOrderByIdDesc();
当然,您可以将 "ById" 部分更改为要用于排序的任何其他字段。
您也可以将其指定为请求的一部分,请查看此处的文档 Sorting。
也请看看类似的回答
也许,你可以:
localhost:3000/api/addresses?sort={property},desc
这将帮助您按 属性 desc
排序