且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 Spring Boot Data Rest 在同一请求中保存多个对象

更新时间:2023-09-09 21:59:34

错误的是试图将您的请求正文作为 Item 读取,而实际上它是多个 Items代码>.

What is wrong is that is trying to read your request body as an Item, when it is in fact multiple Items.

我相信您在这里有两个选择.在这种情况下,我通常会做的是创建另一个资源,例如 ItemCollection,以包装多个 Items.然后,您可以使用标准的 REST 功能来接收 ItemCollection,它基本上可以处理多个 Items.

I believe you have two choices here. What I would normally do in this situation would be to create another resource, such as ItemCollection, to wrap multiple Items. Then you could have standard REST functionality to take in an ItemCollection, which would essentially handle multiple Items.

您的第二个选择是手动覆盖处理多个项目的方法:http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-响应处理程序

Your second option would be to manually override a method to handle multiple itmes: http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers