场景:ajax访问controller,返回数据中文乱码
解决:
1、注解添加属性,对单个方法作用
@RequestMapping(value="/getUserList",produces = "text/html;charset=UTF-8")
2、mvc:annotation-driven添加配置信息
<mvc:annotation-driven>
<!-- 解决@ResponseBody中文乱码 -->
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8"></constructor-arg>
<!-- <property name="supportedMediaTypes" value="text/html;charset=UTF-8"></property>-->
<!-- 去除响应头Accept-Charset -->
<property name="writeAcceptCharset" value="false"></property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
未添加writeAcceptCharset:
添加后:
其他参考:http://tchen8.iteye.com/blog/993504