2014-11-20 64 views
0

我正在尝试编写一个REST PUT方法,我不知道如何获取请求者发送的主体。例如,他将发送一个序列化为JSON的Person对象,并且我想将JSON序列化回Person对象。Spring MVC - PUT - JSON序列化为Java对象

我找不到太多的春天里,但这里是我有:

@RequestMapping(method = RequestMethod.PUT) 
    public Person registerPerson(@PathVariable String siteId, @ModelAttribute("personForm") Person user) throws Exception { 

     //some Logic 

    } 

我不认为我正确地做这个。 @ModelAttribute是否自动序列化?

+0

_body的requestor_看看'@ RequestBody'。 – 2014-11-20 16:43:02

+0

@SotiriosDelimanolis在哪里我会把它放在请求映射的顶部? – Alan 2014-11-20 16:45:51

+1

http://stackoverflow.com/questions/11291933/requestbody-and-reponsebody-spring – 2014-11-20 16:46:42

回答

0

试试这个:

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

     //some Logic 

    }