Spring Data REST 将导出其所有属性(id 除外). [英] Spring Data REST will export all its attributes (except the id).

查看:27
本文介绍了Spring Data REST 将导出其所有属性(id 除外).的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前处于 Spring Data Rest 的学习阶段.我开发了一个应用程序,在其中我能够成功地公开 Rest Respoitory,但没有ID".我在互联网上搜索以检查我是否做错了什么.但是,官方链接之一(Official Doc) 说,Spring Data REST 将导出其所有属性(id 除外).您可以通过定义一个或多个投影为 REST 服务的使用者提供替代方案."所以如果有十多个实体.我必须创建十个投影才能显示它.还有其他方法可以实现吗?

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 ?

推荐答案

Spring Data REST 假定使用 HATEOAS,因此每个资源都必须有一个带有其 ID 的自引用.这就是资源没有 ID 的原因.

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.

但是您可以使用 RepositoryRestConfigurerAdapter:

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);
  }
}

更多信息:1, 2

这篇关于Spring Data REST 将导出其所有属性(id 除外).的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆