Spring MVC 4.1.0配置Jackson

来源:互联网 发布:mysql pdf 微盘 编辑:程序博客网 时间:2024/06/05 02:38

Spring MvC 4.1.0 使用@ResponseBody返回json格式 ,必须进行以下配置:

1. 将jackson-annotations-2.6.0.jar、jackson-core-2.6.0.jar、jackson-databind-2.6.0.jar复制到项目WebRoot----WEB-INF----lib文件夹下

2.配置springmvc-servlet.xml

   <!-- 配置json--> 
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
        <bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
<value>text/xml;charset=UTF-8</value>
<value>text/plain;charset=UTF-8</value>
<value>text/javascript;charset=UTF-8</value>
<value>application/vnd.ms-excel;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>


3.配置成功,可以正常返回json


备注:Spring Mvc4.1以上必须使用Jackson 2.6版本


原创粉丝点击