解決JSON返回到瀏覽器出現中文亂碼顯示???的問題

在使用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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章