标签:springmvc json jackson下载 jackson
坑一:官方网站下载地址不明朗,最后找了几个下载地址:http://wiki.fasterxml.com/JacksonDownload
Jackson2.5下载地址:jackson2.5.0.jar
坑二:配置文件的配置信息跟jackson的版本有关。
版本一: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
版本二:org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
SpringMVC返回json配置步骤如下:
1、添加jackson.jar包
2、在applicationContext.xml配制文件中添加如下代码
<!--解析返回JSON -->
<!-- <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list >
<ref bean="mappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
3、在controller中添加如下代码
@RequestMapping(value="/chinese/listTree", method = RequestMethod.POST)
@ResponseBody
public List getlistChinese(Model model){
List<User> list = (List<ChineseCategory>) commonMgr.find("from User");
return list;
}
返回值可以为list也可以为Map类型
标签:springmvc json jackson下载 jackson
原文地址:http://blog.csdn.net/caiwenfeng_for_23/article/details/43492973