ZTree async中文乱码,ZTree reAsyncChildNodes中文乱码,zTree中文乱码

ZTree async中文乱码,ZTree reAsyncChildNodes中文乱码,zTree中文乱码

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

©Copyright 蕃薯耀 2017年7月27日

http://fanshuyao.iteye.com/

 

一、问题描述

使用zTree的异步刷新父级菜单时,服务器返回中文乱码,但项目中使用了SpringMvc,已经对中文乱码处理,为什么还会出现呢?

 

此处为的异步请求的配置:

async: {
    enable: true,
    url: basePath + '/sysMenu/listSysMenu',
    autoParam: ["id=parentId"]
}

 

 

SpringMvc中文字符处理:

<mvc:annotation-driven>
    <mvc:message-converters>
    <bean class="org.springframework.http.converter.StringHttpMessageConverter">
        <property name="supportedMediaTypes">
             <list>
                    <value>application/json;charset=UTF-8</value>
		    <value>text/html;charset=UTF-8</value>
	     </list>
        </property>
   </bean>
  </mvc:message-converters>
</mvc:annotation-driven>

 

 

返回的结果有中文乱码:

[
    {
        "menuId": "880095098165986816",
        "menuName": "????",
        "parentId": "880095098165986815",
        "menuUrl": "http://localhost:8080/imovie-manage/sysMenu/listSysMenuUI",
        "menuIcon": "",
        "menuSort": 1,
        "isEnable": 1,
        "parentMenuName": "??",
        "id": "880095098165986816",
        "name": "????",
        "pId": "880095098165986815"
    },
    {
        "menuId": "880095098165986817",
        "menuName": "???????",
        "parentId": "880095098165986815",
        "menuUrl": "http://localhost:8080/imovie-manage/sysMenu/treeSysMenuUI",
        "menuIcon": "",
        "menuSort": 1,
        "isEnable": 1,
        "parentMenuName": "??",
        "id": "880095098165986817",
        "name": "???????",
        "pId": "880095098165986815"
    }
]

 

二、解决方案

经过排查,发现是SpringMvc中文字符处理的supportedMediaTypes少了一种类型。

从浏览器发送的请求来看:



 

异步刷新使用的是post请求,但从服务器返回的时候,Content-Type为:text/plain;charset=ISO-8859-1

charset是ISO-8859-1,而不是UTF-8,而SpringMvc处理的中文乱码没有包含这种类型,所以导致中文乱码。

 

所以最后的解决方法是在SpringMvc中文处理加上text/plain这个类型,如下:

<value>text/plain;charset=UTF-8</value>

 具体如下:

<property name="supportedMediaTypes">
    <list>
        <value>application/json;charset=UTF-8</value>
	<value>text/html;charset=UTF-8</value>
	<value>text/plain;charset=UTF-8</value>
    </list>
</property>

 

然后问题就这样解决了。^_^

 

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

©Copyright 蕃薯耀 2017年7月27日

http://fanshuyao.iteye.com/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值