解决@ResponseBody注解返回的json中文乱码问题

1. 简介

主要解决@ResponseBody注解返回的json中文乱码问题

2.解决方案

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

在mvc配置文件中假如下面配置(写在

<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")

猜你喜欢

转载自www.cnblogs.com/huanghuizhou/p/9109155.html