@ResponseBody乱码的解决方案比较简单,只要在spring的配置文件中,增加如下配置即可
01 | <!--启动Spring MVC的注解功能,完成请求和注解POJO的映射并且设置ResponseBody返回编码 --> |
02 | < bean class = "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" /> |
03 | < bean class = "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" > |
04 | < property name = "messageConverters" > |
05 | < list > |
06 | < bean class = "org.springframework.http.converter.StringHttpMessageConverter" > |
07 | < constructor-arg > |
08 | < bean class = "org.springframework.beans.factory.config.MethodInvokingFactoryBean" > |
09 | < property name = "targetClass" value = "java.nio.charset.Charset" /> |
10 | < property name = "targetMethod" value = "forName" /> |
11 | < property name = "arguments" value = "UTF-8" /> |
12 | </ bean > |
13 | </ constructor-arg > |
14 | </ bean > |
15 | </ list > |
16 | </ property > |
17 | </ bean > |
本文转自 http://www.jeasyuicn.com/spring3x--notes-return-garbled-solution.html