空或为空时,Spring Data ReST ref链接遗漏 [英] Spring Data ReST ref link omission when null or empty

查看:82
本文介绍了空或为空时,Spring Data ReST ref链接遗漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索文档和 Oliver实施的Restbucks ,但我没有似乎能够在生成的Spring REST存储库资源上配置链接. (我可以添加它们,但是不能通过ResourceProcessor删除它们,因为在外观转换之前,处理器是在调用处理器的.)

I've been scouring the docs and the Restbucks implementation by Oliver but I don't seem to be able to configure the links on a generated Spring REST repository resource. (I can add to them, but cannot remove them via the ResourceProcessor as the processor is invoked prior to conversion by the looks of things)

我的情况很简单,就是我希望在指向null或空集合的对象上省略rel链接(例如在图节点父/子结构的情况下)

My case is quite simple and that is I wish to omit rel links on objects that point to null or an empty collections (such as in the case of say a graph node parent/child structure)

有人会煽动我如何实现这一目标吗?理想情况下,我想在Restbucks README中提出一些建议(但我找不到使用的建议),在该案例中,将拾取自定义的RestResourceEntityLinks扩展,并根据我的情况将上述实现中生成的链接应用于所有域对象.

Would anybody have any incite as to how I could achieve this? Ideally I would like to have something suggested in the Restbucks README (but I cannot find it used) where a custom RestResourceEntityLinks extension would be picked up and links generated from said implementation as my case applies to all domain objects.

但是也许还有一种更简单的方式我还没有遇到?还是让这些链接指向一个空数组或null就是有效的仇恨参考,所以我应该将其保留并继续前进?

But perhaps there is an easier way that I am yet to come across? Or perhaps having these links point to an empty array or null is a valid hateoas ref so I should just leave it be and move on?

预先感谢

推荐答案

通常来说,您应该能够通过仅调用Resource.getLinks()并与返回的List混淆来删除链接.如果您认为Resource.removeLink(String rel)有意义,请随时为此创建票证.

Generally speaking you should be able to remove links by just calling Resource.getLinks() and mess with the List returned. If you think a Resource.removeLink(String rel) makes sense, feel free to create a ticket for that.

但是,我认为指向空资源的链接是有意义的,因为链接的存在在告诉客户可以与之交互的相关资源方面起着重要作用.换句话说:如果链接不可用,客户端将如何发现分配相关资源或向当前空集合中添加元素的可能性.

However, I'd argue the links pointing to empty resources makes sense as the presence of links has an important role in telling the client that there's a related resource it can interact with. In other words: if the link is not available, how would the client find out about the possibility to assign a related resource, or to add an element to the currently empty collection.

链接不仅表示资源的当前状态,而且表示对客户端接下来/可以做的事情的支持.以 payment链接.如果还没有付款,它只是存在.完成后,链接甚至消失.实际上,这与您要拍摄的内容相反:

Links are not only representing the current state of the resource but affordances to what the client shall/can do next. Take the payment link in the RESTBucks project for example. It's only present, if no payment has been placed yet. Once done, the link even disappears. That's actually the opposite of what you're shooting for :).

这篇关于空或为空时,Spring Data ReST ref链接遗漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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