今天自己搭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