弄了大概七八个小时吧

都他妈比的抄来抄去,一分一秒的去试错

最终参考这个问题解决了乱码的情况https://bbs.csdn.net/topics/392169549

412

需要在springmvc中添加如下配置(我都使用的utf-8)

  <!-- string乱码 -->
<bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="utf-8" index="0"/>
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=utf-8</value>
</list>
</property>
</bean> <!-- fastJson配置 -->
<bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/json;charset=utf-8</value>
<value>text/html;charset=utf-8</value>
</list>
</property>
</bean> <!-- 请求处理器 -->
<mvc:annotation-driven>
<mvc:message-converters>
<ref bean="fastJsonHttpMessageConverter"/>
<ref bean="stringHttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven> <!--fastJsonConfig -->
<bean id="fastJsonConfig" class="com.alibaba.fastjson.support.config.FastJsonConfig">
<!--默认编码格式 -->
<property name="charset" value="UTF-8"/> <property name="serializerFeatures">
<list>
<value>WriteNullListAsEmpty</value>
<value>WriteDateUseDateFormat</value>
<value>PrettyFormat</value>
<value>WriteMapNullValue</value>
<value>WriteNullStringAsEmpty</value>
<value>WriteNullListAsEmpty</value>
<value>DisableCircularReferenceDetect</value>
</list>
</property> </bean>
<!--fastjson支持配置结束 -->

至于mvc自带的jackson的配置,自动转换的配置写不写都无所谓了

控制器这样写

如果有

produces= "application/json;charset=UTF-8"

或者这个写法

produces= {"application/json;charset=UTF-8"}

完成以上配置才能正确返回中文,特别是控制器上的那一串,一定要写,

返回数据如下

如果没有上边那句话

就成了这样的

太晚了,睡觉,明天在研究

乱码问题解决,别的就都好说了

如果不适用return ,也可以这样写

        response.setContentType("text/html;charset=utf-8");
response.getWriter().write(json);

发出来的也是这样的

1

Springmvc使用阿里巴巴的fastjson传输到前台中文乱码的解决方案,他娘的大家都少制造垃圾,学习过程将会多么快乐的更多相关文章

  1. spring boot 解决后台返回 json 到前台中文乱码之后出现返回json数据报错 500:no convertter for return value of type

    问题描述 spring Boot 中文返回给浏览器乱码 解析成问号?? fastJson jackJson spring boot 新增配置解决后台返回 json 到前台中文乱码之后,出现返回json ...

  2. SpringMVC学习系列-后记 解决GET请求时中文乱码的问题

    SpringMVC学习系列-后记 解决GET请求时中文乱码的问题 之前项目中的web.xml中的编码设置: <filter> <filter-name>CharacterEnc ...

  3. springMVC获取数据--注意post方法会出现中文乱码问题

    1. 新建web project 2. 加入jar 3. 改写web.xml <?xml version="1.0" encoding="UTF-8"?& ...

  4. SSM框架:解决后台传数据到前台中文乱码问题,使用@ResponseBody返回json 中文乱码

    解决方法一:@RequestMapping(value="/getphone",produces = "text/plain;charset=utf-8") / ...

  5. springmvc中的web.xml配置(包含中文乱码解决)

    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http:// ...

  6. xml传输过程中中文乱码

    ------------------------------------------request:----------------------------------------------- pu ...

  7. springmvc配置一:ajax请求防止返回中文乱码配置说明

    Spring3.0 MVC @ResponseBody 的作用是把返回值直接写到HTTP response body里. Spring使用AnnotationMethodHandlerAdapter的 ...

  8. 解决SpringMvc后台接收json数据中文乱码问题

    原因分析 使用ajax从前台页面传输数据到后台controller控制器的时候,出现中文乱码 其实乱码问题出现的原因,就是由于默认的tomcat配置,接收请求是以ISO-8859-1来转码,导致中文出 ...

  9. springmvc项目中的中文乱码的解决及未生效解决

    情景: springmvc项目中,在控制台输出时中文乱码,在web网页中正常. 解决方法: 在web.xml中添加如下代码: <!-- 中文乱码解决 --> <filter> ...

随机推荐

  1. STL vector容器需要警惕的一些坑

    从迭代器中取值切记需要判断是否为空 例如: vector<int> vtTest; vtTest.clear(); if (vtTest.empty()){ ; } ]; 如果没有忘了判断 ...

  2. 修改文本框和文本域placeholder样式

    input::-webkit-input-placeholder, textarea::-webkit-input-placeholder { font-size:20px; padding:20px ...

  3. C++数组或vector求最大值最小值

    可以用max_element()及min_element()函数,二者返回的都是迭代器或指针. 头文件:#include<algorithm> 1.求数组的最大值或最小值 1)vector ...

  4. Error-Idea:Process finished with exit code 1

    ylbtech-Error-Idea:Process finished with exit code 1 1.返回顶部 1. log4j:WARN No appenders could be foun ...

  5. Django之模板语言(二)-----Filter

    1.其他常用的模板语言: 通过模板语言可以让前端页面显示数据,数据可以是基本数据类型,也可以是对象亦或者对象的列表,结合着模板中的for.if等配合使用. 要注意前端页面中,出现没有后端数据的情况,随 ...

  6. Neo4j-Cypher语言语法

    Neo4j-Cypher语言语法 梦飞扬 2018-03-15 264 阅读 Neo4j 本文是记录Neo4j图数据库中实用的Cypher语言语法. Cypher是什么 "Cypher&qu ...

  7. NoSQL 图形数据库

  8. Django项目:CRM(客户关系管理系统)--80--70PerfectCRM实现CRM业务流程(bpm)课程排行分页

    # coursetop_views.py # ————————64PerfectCRM实现CRM课程排名详情———————— #————班级学生详情——#计算#{学员ID:分数}——#计算 #{学员I ...

  9. CGLayer和CALayer区别

    CGLayer是一种很好的缓存常绘内容的方法.注意,不要与CALayer混淆.CALayer是Core Animation中更加强大.复杂的图层对象,而CGLayer是Core Graphics中优化 ...

  10. light oj 1079 01背包

    #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...