坑一:官方網站下載地址不明朗,最後找了幾個下載地址:http://wiki.fasterxml.com/JacksonDownloadhtml
Jackson2.5下載地址:jackson2.5.0.jarweb
坑二:配置文件的配置信息跟jackson的版本有關。spring
版本一: org.springframework.http.converter.json.MappingJacksonHttpMessageConverterjson
版本二:org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
mvc
SpringMVC返回json配置步驟以下:app
一、添加jackson.jar包網站
二、在applicationContext.xml配製文件中添加以下代碼spa
<!--解析返回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>
.net
三、在controller中添加以下代碼xml
@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類型