在使用Spring MVC做項目時,使用@ResponseBody註解返回JSON串,但是將JSON返回給前端進行處理時,啓動tomcat並在瀏覽器訪問時出現???亂碼。
解決方案
方案一
在相應的請求註解上添加參數produces = "application/json; charset=utf-8"
方案二
在SpringMVC的配置文件中的<mvc:annotation-driven>
中加入<mvc:message-converters>
的配置
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list><value>text/plain;charset=utf-8</value></list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>