使用AJAX调用Spring controller 并返回map对象,@ResponseBody 只能返回string的解决方案:

来源:互联网 发布:知乎66条神回复集锦 编辑:程序博客网 时间:2024/05/21 22:48
使用AJAX调用Spring controller 并返回map对象,@ResponseBody 只能返回string的解决方案:
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包,

jackson-mapper-asl-1.9.12.jar
jackson-core-asl-1.9.12.jar

这样@ResponseBody终于可以返回给AJAX Map,或List对象了。

阅读全文
0 0