如何将列表发布到Spring Data Rest? [英] How to post a list to Spring Data Rest?

查看:137
本文介绍了如何将列表发布到Spring Data Rest?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了此示例,它允许发布唯一的Person对象.我想要一个REST服务,可以一次发布Person的集合,例如一次调用一个名为Team的列表/任何集合,其中包含许多Person对象.

我的意思是,我的问题不完全是关于OneToMany关系的问题,在这个关系中,您在REST请求中发送每个人.这个主题很好回答. >

我想利用@RepositoryRestResource或Spring Data Rest的另一个功能来发送Person对象的集合.使用Spring Data Rest可以做到这一点吗?还是应该通过创建一个控制器来解决该问题,接收该列表并解析Team列表以插入每个Person?

我发现了此功能请求,这似乎可以回答如今的Spring Rest Data找不到我想要的东西,但我不确定.

根据我的业务需求,应用程序A将向应用程序B发布订单列表,并且我必须将其保存在数据库中以供将来处理,因此,在阅读了有关Spring Data Rest并制作了一些示例之后,我发现其干净的体系结构令人惊叹并且非常适合我的要求,除了我不知道如何发布列表.

解决方案

好吧,AFAIK使用spring data rest无法做到这一点,只需阅读文档,您会发现,没有提到将列表发布到收集资源.

原因尚不清楚,但有一点-REST本身并没有真正指定您应该如何进行批处理操作. 因此,目前尚不清楚应该如何使用该功能,例如是否应该发布一个列表来收集资源?还是应该导出像/someentity/batch这样的资源,该资源可以批量修补,删除和添加实体?如果要添加列表,应如何返回ID?对于单个POST收集spring-data-rest,在Location标头中返回ID.对于批量添加,无法完成.

这并不能证明spring-data-rest缺少批处理操作.他们应该实施此恕我直言,但至少可以帮助他们理解为什么会遗漏它.

我可以说的是,您总是可以将自己的Controller添加到可以正确处理/someentity/batch的项目中,甚至可以从中创建一个库,以便可以在其他项目中使用它.甚至是fork spring-data-rest并添加此功能.尽管我试图了解它是如何工作的,但到目前为止还是失败了. 但是您可能知道所有这些,对吧?

对此有功能要求.

I followed this example, which allows to post a unique Person object. I want a REST service where I can post a collection of Person at once, e.g. a list/any collection named Team with numerous Person objects in just one call.

I mean, my question is not exactly about the OneToMany relationship, where you send each person in a REST request. This topic is well answered.

I want to send a collection of Person objects taking advantage of @RepositoryRestResource or another feature from Spring Data Rest. Is this possible with Spring Data Rest or should I workaround by creating a controller, receive the list and parse the Team list to insert each Person?

I found this feature request, which seems to answer that nowadays Spring Rest Data is missing what I am looking for, but I am not sure.

In my business requirement, application A will post a list of orders to application B and I have to save it in database for future processing, so, after reading about Spring Data Rest and making some samples, I found its clean architecture amazing and very suitable for my requirement except for the fact that I didn't figure out how to post a list.

解决方案

Well, AFAIK you can't do that with spring data rest, just read the docs and you will see, that there is no mention about posting a list to collection resource.

The reason for this is unclear to me, but for one thing - the REST itself doesn't really specify how you should do batch operations. So it's unclear how one should approach that feature, like should you POST a list to collection resource? Or should you export resource like /someentity/batch that would be able to patch, remove and add entities in one batch? If you will add list how should you return ids? For single POST to collection spring-data-rest return id in Location header. For batch add this cannot be done.

That doesn't justify that spring-data-rest is missing batch operations. They should implement this IMHO, but at least it can help to understand why are they missing it maybe.

What I can say though is that you can always add your own Controller to the project that would handle /someentity/batch properly and you can even probably make a library out of that, so that you can use it in another projects. Or even fork spring-data-rest and add this feature. Although I tried to understand how it works and failed so far. But you probably know all that, right?

There is a feature request for this.

这篇关于如何将列表发布到Spring Data Rest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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