Reputation: 644
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>
{
}
Upvotes: 4
Views: 6047
Reputation: 136
Perhaps,you can :
localhost:3000/api/addresses?sort={property},desc
this will help you sort by property desc
Upvotes: 7
Reputation: 846
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.
Upvotes: 4
Reputation: 938
Try inside the AddressRepository class something like:
public List<Address> findAllByOrderByIdDesc();
of course you can change the "ById" part with any other field you want to use for sorting.
Upvotes: 0