当我在Spring框架中创建任何存储库时,它会提供默认方法来使用此API获取实体的所有记录:
GET : http://localhost:3000/api/addresses
它按升序发送数据,但如果我想按降序排列数据,该怎么做呢?
地址存储库
public interface AddressRepository extends JpaRepository<Address, Long>
{
}
当我在Spring框架中创建任何存储库时,它会提供默认方法来使用此API获取实体的所有记录:
GET : http://localhost:3000/api/addresses
它按升序发送数据,但如果我想按降序排列数据,该怎么做呢?
地址存储库
public interface AddressRepository extends JpaRepository<Address, Long>
{
}
localhost:3000/api/addresses?sort={property},desc
这将帮助您按属性降序排序
public List<Address> findAllByOrderByIdDesc();
当然,您可以将“ById”部分更改为任何其他要用于排序的字段。