【发布时间】:2014-11-20 16:41:45
【问题描述】:
我正在尝试编写一个 REST PUT 方法,但我不确定您如何获得请求者发送的正文。例如,他要发送一个序列化为 JSON 的 Person 对象,而我想将 JSON 序列化回一个 Person 对象。
我在 Spring PUT 上找不到太多信息,但这是我所拥有的:
@RequestMapping(method = RequestMethod.PUT)
public Person registerPerson(@PathVariable String siteId, @ModelAttribute("personForm") Person user) throws Exception {
//some Logic
}
我不认为我这样做是正确的。 @ModelAttribute 会自动序列化吗?
【问题讨论】:
-
请求者的正文查看
@RequestBody。 -
@SotiriosDelimanolis 我应该把它放在请求映射的顶部吗?
-
@SotiriosDelimanolis 啊……谢谢。这很有帮助。
标签: java json spring spring-mvc serialization