Reputation: 653
I'm pretty new to Spring Data Rest and Spring in general. I use Spring Data Rest with Spring Data Jpa and a Mysql DataBase.
I can't find how to change the Entity property used as Id in the URL. Here basically what i'm trying to achieve:
I have the following entity: Plant(id,code,name,...)
Actually i obtain a plant item resource using
GET /plants/:id
I would like to access to this resource item using:
GET /plants/:code
Plant.code
property is not the official id
of the entity but is unique and makes much more sense to the final user of the API.
I have searched through the documentation and Google/SO but have not found any relevant answer.
So excuse me if the anwser is obvious
Upvotes: 3
Views: 628
Reputation: 4738
You could add a search endpoint like this, which returns a single matching resource:
GET /plants/search/findByCode?code=:code
You would do this by adding this to your repository interface:
Plant findByCode(@Param("code") String code);
Upvotes: 1