spring mvc @ResponseBody返回中文乱码解决
来源:互联网 发布:列宁格勒保卫战知乎 编辑:程序博客网 时间:2024/04/29 03:29
sping mvc中添加@ResponseBody,返回中文字符串时出现乱码,且在applicationContext-web.xml中已经配置StringHttpMessageConverter
<span style="white-space:pre"></span><!-- 避免返回中文时出现乱码 --><bean id="stringHttpMessageConverter" 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>
<span style="white-space:pre"></span><bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"><span style="white-space:pre"></span><property name="messageConverters"><span style="white-space:pre"></span><list><span style="white-space:pre"></span><ref bean="stringHttpMessageConverter"/><span style="white-space:pre"></span><ref bean="mappingJackson2HttpMessageConverter"/><span style="white-space:pre"></span><ref bean="marshallingHttpMessageConverter"/><span style="white-space:pre"></span></list><span style="white-space:pre"></span></property><span style="white-space:pre"></span></bean>
但是出现乱码,原因是因为将<mvc:annotation-driven/>配置放在了RequestMappingHandlerAdapter配置的前边了,导致后边配置的StringHttpMessageConverter配置无效,解决办法,因为<mvc:annotation-driven/>默认也会加载RequestMappingHandlerAdapter,所以需要把<mvc:annotation-driver/>放置到RequestMappingHandlerAdapter配置的后边,中文乱码的问题解决。
注:spring MVC 3.1之后,@RequestMapping
methods called RequestMappingHandlerMapping
and RequestMappingHandlerAdapter
,Prior to Spring 3.1, type and method-level request mappings were examined in two separate stages — a controller was selected first by theDefaultAnnotationHandlerMapping
and the actual method to invoke was narrowed down second by the AnnotationMethodHandlerAdapter
.
- spring mvc @ResponseBody返回中文乱码解决
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- spring-mvc @responseBody注解返回中文乱码解决
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- Linux下QT+Python
- ArrayAdapter--SimpleAdapter--ListView
- Are you happy?
- 海康摄像头视频实时监控
- WPF Chart DynamicDataDisplay的横坐标显示日期的解决方案
- spring mvc @ResponseBody返回中文乱码解决
- 王爽《汇编语言》实验9详解
- hjr教程-PHP(三):PDO连接Mysql
- 题目1106:数字之和
- PHP中插件机制的一种实现方案
- solr的多条件组合查询和solr的范围查询
- Hibernate(基础一) Hibernate3的动态条件查询DetachedCriteria用法
- Android6.0权限组
- n个元素的所有子集(递归+非递归 +不去重)