Search code examples
springrestsortingspring-data-jpaspring-data-rest

How to Use sorting in Spring Data Rest GET method


When I create any repository in spring framework like following it gives method by default to get all records of the entity using this API

GET : http://localhost:3000/api/addresses

It sends data from ascending order But If I want my data in descending order than How can I specify this ?

Address Repository

    public interface AddressRepository extends JpaRepository<Address, Long> 

    {
    }

Solution

  • You can also specify this as part of your request, take a look at documentation here Sorting.

    Also please take a look at similar answer here.