@ResponseBody 返回中文乱码
第一种解决方法:在@RequestMapping注解添加produces属性
第二种:在配置文件中配置
如果你的是spring3.x使用MappingJacksonHttpMessageConverter,
如果你的是spring4.x使用MappingJackson2HttpMessageConverter。
导入需要的jar包:jackson-annotations-2.50.jar,jackson-core-2.5.0.jar,jackson-databind-2.5.0.jar
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=utf-8</value>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
或者在文件中配置,但是一定要在<mvc:annotion-deriven></mvc:annotation-driven>的上面,不然不起作用:
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" >
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=utf-8</value>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>