如何向客户端提供资源ID?

时间:2014-09-30 06:55:25

标签: spring spring-hateoas hypermedia

org.springframework.hateoas.ResourceSupport已包含getId方法。

如果我的资源(或更好的域对象)包含需要呈现给客户端的整数ID,我无法添加简单的id并添加getId / setId(如ResourceSupport已经拥有它。)

我应该返回<myResourceObjectName>_id内容还是让客户解释ResourceSupport提供的ID链接/网址更好?

2 个答案:

答案 0 :(得分:3)

出于客户端的目的,最初从(通过GET)检索资源的URL是其id。不应该进行解释,客户端应将URL视为不透明的字符串。

答案 1 :(得分:0)

您想要查看此文章how-to-expose-the-resourceid-with-spring-data-rest

 @Configuration
public class MyCoolConfiguration extends RepositoryRestMvcConfiguration {

    @Override
    protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
        config.exposeIdsFor(FooEntity.class);
    }
}
相关问题