问题
I am currently in learning phase of Spring Data Rest. I developed one app in which I was able to succesfully expose the Rest Respoitory but with out the "ID". I searched over the internet to check if I am doing any thing wrong. However, one of the officially links (Official Doc) says, "Spring Data REST will export all its attributes (except the id). You can offer the consumer of your REST service an alternative by defining one or more projections." So if have more than ten entities. I have to create ten projections to get it displayed. Is there any other way to achieve it ?
回答1:
Spring Data REST assumes the using of HATEOAS, so every resource must have a self reference with its ID. That's why resources don't have ids.
But you can turn it on with configureRepositoryRestConfiguration
method of RepositoryRestConfigurerAdapter:
@Component
public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.exposeIdsFor(MyEntity1.class, MyEntity2.class);
}
}
More info: 1, 2
来源:https://stackoverflow.com/questions/50798326/spring-data-rest-will-export-all-its-attributes-except-the-id