2014-11-20 65 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 

    }