-1

这是我的控制器的代码。

@RequestMapping(value="/save", method=RequestMethod.POST )
public ModelAndView  saveArticle(@ModelAttribute Article article, BindingResult result) {
                     System.out.println("inside controller"+article.getArticleName()+"  "+article.getArticleDesc());
                     int a=articleService.addArticle(article);

                    if(a==1)
                    {
                        return new ModelAndView("success");
                    }
                    else
                    {
                        return new ModelAndView( "error");
                    }
                     /*else if(a==0){
                         return new ModelAndView("error");
                     }*/
                    //return new ModelAndView("redirect:/articles.html");
        }

如何获取json格式发送的articleName和desc,然后转换成java对象?

4

1 回答 1

0

您可以使用@RequestBody注释。

http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/web/bind/annotation/RequestBody.html

您还可以包括jackson来序列化/反序列化对象。

@RequestMapping(value="/save", method=RequestMethod.POST )
public ModelAndView  saveArticle(@RequestBody Article article, BindingResult result) {
    ...
}
于 2013-05-06T10:06:32.883 回答