springmvc 使用fastjson 处理 json 数据时中文乱码

来源:互联网 发布:修复sql注入漏洞 编辑:程序博客网 时间:2024/05/21 18:40

原因:
springmvc在处理请求时,默认采用的是 ISO-8859-1 编码格式,具体原因不了解,个人觉得是还没有来得及更改,所以在处理一些json格式的时候,会出现中文乱码。

org.springframework.http.converter.StringHttpMessageConverter类是处理请求或相应字符串的类,并且默认字符集为ISO-8859-1,所以在当返回json中有中文时会出现乱码。

配置解决:

<!-- 处理请求时返回json字符串的中文乱码问题 -->    <mvc:annotation-driven>        <mvc:message-converters>            <bean class="org.springframework.http.converter.StringHttpMessageConverter">                <property name="supportedMediaTypes">                    <list>                        <value>application/json;charset=UTF-8</value>                    </list>                </property>            </bean>        </mvc:message-converters>    </mvc:annotation-driven>
0 0
原创粉丝点击