@Responsebody註解返回json字符串中文亂碼

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章