Spring @ResponseBody只能返回String类型数据解决办法

今天自己搭Spring MVC框架玩,使用AJAX调用Spring controller 并返回map对象,突然发现,哎,怎么@Response中只能返回String, 我用的Spring 3的版本也不低啊,百思不得其解,遂去官方论坛查找原因,好家伙,好多人都有这个经历,而且貌似有些官方人员也说不清怎么解决,人家提问题的都嚷嚷着要去提交bug了(看来官方支持人员也有渣渣啊)。
于是去spring-vramework官网查看文档,有如下描述
Jackson  is supported directly on @ResponseBody and ResponseEntity controller methods for serializing different amounts of detail for the same POJO (e.g. summary vs. detail page). This is also supported with View-based rendering by adding the serialization view type as a model attribute under a special 。
靠,这说明如果使用@ResponseBody ,jackson是需要引用进来的啊。
有了这个指引,就好说了,我倒入了如下的两个jar包,OK,问题解决,@ResponseBody终于可以返回给AJAX Map,或List对象了。

jackson-mapper-asl-1.9.12.jar
jackson-core-asl-1.9.12.jar
posted @ 2016-06-19 14:11  汪强胜  Views(3871)  Comments(0Edit  收藏  举报