解決@ResponseBody注解返回的json中文亂碼問題


1. 簡介

主要解決@ResponseBody注解返回的json中文亂碼問題。

2.解決方案

2.1mvc加上注解(推薦此方法)

在mvc配置文件中假如下面配置(寫在 <mvc:annotation-driven/>之前才有效)



<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.2 使用@RequestMapping注解的produces方法

@RequestMapping(value = "testPersonalValidtor.do",produces = "application/json;charset=utf-8")


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM