Spring Data REST will export all its attributes (except the id).

若如初见. 提交于 2020-01-16 12:35:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!