在使用@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字符串不會出現亂碼,不能做到全局控制。