斯普林·罗& JSON:定义基于数组的删除、更新操作
我用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太确定你在问什么,但你绝对可以使用 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.