弄了大概七八个小时吧

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

最终参考这个问题解决了乱码的情况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. 使用应用程序(Java/Python)访问MaxCompute Lightning进行数据开发

    MaxCompute Lightning是MaxCompute产品的交互式查询服务,支持以PostgreSQL协议及语法连接访问Maxcompute项目,让您使用熟悉的工具以标准 SQL查询分析Max ...

  2. python mysql数据库中 json的存储

    首先数据库里的字段类型需要设置为json: 存储这个json时需要把这个json变为字符串,而且是最外层为单引号,内部字符串为双引号!如图:  所以python脚本中这个字段的字符串应该这样写: 得出 ...

  3. lvs + keepalived + nginx + tomcat高可用负载反向代理服务器配置(二) LVS+Keepalived

    一.安装ipvs sudo apt-get install ipvsadm 二.安装keepalived sudo apt-get install keepalived 三.创建keepalived. ...

  4. a common method to rotate the image

    /* * clockwise rotate * first reverse up to down, then swap the symmetry * 1 2 3 7 8 9 7 4 1 * 4 5 6 ...

  5. nginx 遇见问题与解决问题

    如果你的安装目录为/usr/local/nginx,那么nginx的错误日志目录就是/usr/local/nginx/logs/error.log. 2.如果error.log不存在 就进入 # vi ...

  6. 101 删除排序数组中的重复数字 II

    原题网址:http://www.lintcode.com/zh-cn/problem/remove-duplicates-from-sorted-array-ii/# 跟进“删除重复数字”: 如果可以 ...

  7. 条件渲染v-if

    <!DOCTYPE html> <html lang="zh"> <head> <title></title> < ...

  8. PAT甲级——A1078 Hashing

    The task of this problem is simple: insert a sequence of distinct positive integers into a hash tabl ...

  9. tar指令集合

    把常用的tar解压命令总结下,当作备忘: tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个, ...

  10. 前端面试题(js部分)

    一.==和===的区别 1.==   用于比较.判断两者相等,比较时可自动换数据类型 2.===  用于(严格)比较.判断两者(严格)相等,不会进行自动转换,要求进行比较的操作数必须类型一致,不一致时 ...