斯普林·罗& JSON:定义基于数组的删除、更新操作

发布于 2024-12-28 05:49:08 字数 645 浏览 4 评论 0原文

我用 roo 实现了一个网络服务。所有查询都运行良好。

删除: 我错过了自动生成的方法来一次删除多个 ID/版本对。调用可能如下所示:

curl -i -X DELETE -H Content-Type:application/json -d [{"id":1,"version":0},{"id":2,"version":0}] http://.../objects

更新: 我还错过了许多条目的更新方法。调用可能与上面相同,但添加了要更新的字段和“-X PUT”。

curl -i -X PUT -H Content-Type:application/json 
 -d [{"id":1,"version":0,"value":"new1"},{"id":2,"version":0,"value":"new2"}] http://.../objects

插入: 在我用 json 插入一个新对象后,有没有办法取回 id 或内容? 当我定义“Accept:application/json”标头时,我得到一个空响应。

我宁愿希望 roo 更新这个方法,然后编写我自己的方法,因为我必须维护很多字段。不然roo就没啥用了。

有没有我可以采用的模板来满足我的需求?

谢谢你!

I implemented a webservice with roo. All queries run fine.

Delete:
I miss a automatic generated method to delete multiple id/version pairs at once. A call could look like this:

curl -i -X DELETE -H Content-Type:application/json -d [{"id":1,"version":0},{"id":2,"version":0}] http://.../objects

Update:
I also miss an update method for many entries. Call could look the same as above but with the fields to update added and "-X PUT".

curl -i -X PUT -H Content-Type:application/json 
 -d [{"id":1,"version":0,"value":"new1"},{"id":2,"version":0,"value":"new2"}] http://.../objects

Insert:
Is there a way to get the id's or the contents back after I inserted an new object with json?
When I define the "Accept:application/json" header I get an empty response.

I rather want roo to update this methods then write my own, since there are many fields I would have to maintain. Otherwise roo would be useless.

Are there any templates I could adopt for my needs?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我只土不豪 2025-01-04 05:49:08

我不太确定你在问什么,但你绝对可以使用 JSON 执行正常的 REST 方法。至于检索 JSON,你也可以这样做。有一个注释,我相信它是 @ResponseBody,您可以在 MVC 方法的前面添加该注释来告诉 Spring“我的响应将包含纯文本,而不是有关返回哪个模板的说明”,然后您只需使用 JSON 方法即可输出 JSON 的实体。

I am not quite sure what you are asking, but you can absolutely do normal REST methods using JSON. As for retrieving JSON, you can do that too. There is an annotation, I believe its @ResponseBody, that you tack on the front of your MVC method to tell Spring "my response will contain plain-text, not instructions on which template to return", then you just use the JSON methods on the Entities to output JSON.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文