@ResponseBody 返回中文乱码
第一种解决方法:在@RequestMapping注解添加produces属性
@RequestMapping(value = "testPersonalValidtor.do",produces = "application/json;charset=utf-8")
第二种:在配置文件中配置
如果你的是spring3.x使用MappingJacksonHttpMessageConverter,
如果你的是spring4.x使用MappingJackson2HttpMessageConverter。
导入需要的jar包:jackson-annotations-2.50.jar,jackson-core-2.5.0.jar,jackson-databind-2.5.0.jar
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
<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>
</mvc:message-converters>
</mvc:annotation-driven>
或者在文件中配置,但是一定要在<mvc:annotion-deriven></mvc:annotation-driven>的上面,不然不起作用:
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" >
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
<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>
@ResponseBody 返回中文乱码的更多相关文章
- 解决SpringMVC的@ResponseBody返回中文乱码
SpringMVC的@ResponseBody返回中文乱码的原因是SpringMVC默认处理的字符集是ISO-8859-1,在Spring的org.springframework.http.conve ...
- Springboot @ResponseBody返回中文乱码
最近我在把Spring 项目改造Springboot,遇到一个问题@ResponseBody返回中文乱码,因为response返回的content-type一直是application/json;ch ...
- SpringMVC @ResponseBody返回中文乱码
SpringMVC的@ResponseBody返回中文乱码的原因是SpringMVC默认处理的字符集是ISO-8859-1, 在Spring的org.springframework.http.conv ...
- Spring @ResponseBody 返回中文乱码问题
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt102 今天在使用spring 的时候,发现中文返回的是乱码. 经过研究发现, ...
- springboot同时支持访问html5和jsp时,导致后台ResponseBody返回中文乱码
背景:原系统是由springboot jsp,所有访问都是jsp 现在需要做HTML5定位,要同时支持访问HTML5和JSP 在application.yml的spring标签下配置 mvc: #vi ...
- @ResponseBody 返回中文乱码问题解决 spingmvc
<!-- UTF8解决乱码问题 --> <bean class="org.springframework.web.servlet.mvc.method.annotation ...
- SpringMVC ResponseBody返回中文乱码解决方案
@RequestMapping(value = "/getForm") @ResponseBody public List<String> getForm(String ...
- 处理springMvc中responsebody返回中文乱码
法一: @RequestMapping(value="/getUsersByPage",produces = public String getUsers 法二:在sprin ...
- @ResponseBody返回中文乱码
1.在方法上修改编码 这种方式,需要对每个方法都进行配置. 2.修改springmvc的配置文件 同时注意,把这个配置写在扫描包的上面.
随机推荐
- The Balance POJ 2142 扩展欧几里得
Description Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of ...
- 混合图(dizzy.pas/cpp/c)
混合图(dizzy.pas/cpp/c) [题目描述] Hzwer神犇最近又征服了一个国家,然后接下来却也遇见了一个难题. Hzwer的国家有n个点,m条边,而作为国王,他十分喜欢游览自己的国家.他一 ...
- 4560 NOIP2015 D2T2 子串 code vs
4560 NOIP2015 D2T2 子串 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 有两个仅包含小写 ...
- 30、Java并发性和多线程-阿姆达尔定律
以下内容转自http://ifeve.com/amdahls-law/: 阿姆达尔定律可以用来计算处理器平行运算之后效率提升的能力.阿姆达尔定律因Gene Amdal 在1967年提出这个定律而得名. ...
- 1.4-动态路由协议OSPF②
LAB2.通过反掩码控制有哪些接口,在运行OSPF ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ step1:启动OSPF,并宣告网络: R1(config ...
- 生成sde
/// <summary> ///获取保存的SDE文件 /// </summary> /// <param name="sdePath">< ...
- Javascript中双等号(==)隐性转换机制 JS里charCodeAt()和fromCharCode()方法拓展应用:加密与解密
Javascript中双等号(==)隐性转换机制 在Javascript中判断相等关系有双等号(==)和三等号(===)两种.其中双等号(==)是值相等,而三等号(===)是严格相等(值及类型是否 ...
- [LeetCode][Java] 4Sum
题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = ...
- HDU1171_Big Event in HDU【01背包】
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- poj2262 Goldbach's Conjecture——筛素数
题目:http://poj.org/problem?id=2262 水水更健康~ 代码如下: #include<iostream> #include<cstdio> #incl ...