Spring HATEOAS嵌入式资源支持 [英] Spring HATEOAS embedded resource support

查看:145
本文介绍了Spring HATEOAS嵌入式资源支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将REST API的HAL格式用于嵌入资源。我正在使用Spring HATEOAS作为我的API,Spring HATEOAS似乎支持嵌入式资源;但是,没有关于如何使用它的文档或示例。

I want to use the HAL format for my REST API to include embedded resources. I'm using Spring HATEOAS for my APIs and Spring HATEOAS seems to support embedded resources; however, there's no documentation or example on how to use this.

有人可以举例说明如何使用Spring HATEOAS来包含嵌入资源吗?

Can someone provide an example how to use Spring HATEOAS to include embedded resources?

推荐答案

我找不到正式的方法来做这个...这就是我们做的事情

I couldn't find an official way to do this...here's what we did

public abstract class HALResource extends ResourceSupport {

    private final Map<String, ResourceSupport> embedded = new HashMap<String, ResourceSupport>();

    @JsonInclude(Include.NON_EMPTY)
    @JsonProperty("_embedded")
    public Map<String, ResourceSupport> getEmbeddedResources() {
        return embedded;
    }

    public void embedResource(String relationship, ResourceSupport resource) {

        embedded.put(relationship, resource);
    }  
}

然后我们的资源扩展HALResource

then made our resources extend HALResource

这篇关于Spring HATEOAS嵌入式资源支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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