在使用@Responsebody注解的时候,发现前台返回的json字符串中,显示的中文出现乱码
1.网上查到很多种方法,我是利用这种方法解决的:
spring-mvc.xml加入以下配置
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<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>
2.这种方法相对比较简单,但是尝试之后没有成功:
@RequestMapping(value = "testPersonalValidtor.do",produces = "application/json;charset=utf-8")
不过这样写的话会有限制,只是局部控制输出json字符串不会出现乱码,不能做到全局控制。