Home ResponseBody响应乱码
Post
Cancel

ResponseBody响应乱码

第一种解决方案是使用@RequestMapping注解的produces方法,写法如下:

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

第二种方法是在Spring的配置文件中修改:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!-- 处理@ResponseBody响应乱码 -->
<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/html;charset=UTF-8</value>  
                      </list>  
                  </property>  
              </bean>  
          </list>  
     </property>  
</bean> 
This post is licensed under CC BY 4.0 by the author.