解决response在controller返回乱码的解决方式

本文来自:SSM框架:解决后台传数据到前台中文乱码问题,使用@ResponseBody返回json 中文乱码

解决response在controller返回乱码的解决方式:
A.在controller的请求头部的注解写上 produces = "text/plain;charset=utf-8" :
     @RequestMapping(value = {"/xxxMethod"},produces = "text/plain;charset=utf-8")
B.在spring-mvc配置:
    <!-- 处理请求返回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>

  

猜你喜欢

转载自blog.csdn.net/zuozhiyoulaisam/article/details/81266108