Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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> 

    {
    }
like image 668
SFAH Avatar asked Dec 24 '22 16:12

SFAH


2 Answers

Perhaps,you can :

localhost:3000/api/addresses?sort={property},desc 

this will help you sort by property desc

like image 169
ChenAn Avatar answered Jan 05 '23 07:01

ChenAn


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.

like image 45
webdizz Avatar answered Jan 05 '23 06:01

webdizz