【问题标题】:Spring MVC - PUT - JSON serialize to Java ObjectSpring MVC - PUT - JSON 序列化为 Java 对象
【发布时间】: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


【解决方案1】:

试试这个:

@RequestMapping(method = RequestMethod.PUT)
    public Person registerPerson(@RequestBody Person user) throws Exception {

        //some Logic

    }

【讨论】:

    猜你喜欢
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    • 2017-12-28
    相关资源
    最近更新 更多