最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

spring+mybatis 通過@ResponseBody返回結(jié)果中文亂碼的解決方法

 更新時間:2017年12月15日 14:12:14   作者:草蛋的小青年  
下面小編就為大家分享一篇spring+mybatis 通過@ResponseBody返回結(jié)果中文亂碼的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

問題發(fā)生:

通過@Responsebody返回

@ResponseBody
@RequestMapping(value ="/selectByFormId",method = RequestMethod.GET)
public Map<String,Object> getClassName(String formId){
  List<String> list =formInfoService.selectClassName(formId);
  Map<String,Object> map = new HashMap<String, Object>();
  map.put("data", list);
  map.put("status", true);
  return map;
}

結(jié)果:

{"data":["璧勮璇瘋喘綾�","淇冮攢綾�","綆$悊綾�","鏆傛敮綾�","鍌ㄨ繍綾�","璧勪駭綾�","璧勮鏈嶅姟綾�","宸梾綆$悊綾�",<br>"閲囪喘綾�","浜轟簨鑰冨嫟綾�","璐㈠姟綾�","瀹㈡埛綾�","瑙嗘嫇綾�","瀹㈣瘔綾�","浜轟簨媧誨姩綾�","浜轟簨琛屾斂綾�","鍏枃綾�",<br>"璇鋒綾�","閿€綆$被","钀ヨ繍涓氬姟綾�"],"status":true}

解決辦法:

在spring-mvc.xml中配置

<!-- 解決ResponseBody 亂碼問題StringHttpMessageConverter這個轉(zhuǎn)換器轉(zhuǎn)換時,父類AbstractHttpMessageConverter的supportedMediaTypes屬性默認(rèn)是iso-8895-1導(dǎo)致 -->           
  <mvc:annotation-driven> 
    <mvc:message-converters> 
      <bean class="org.springframework.http.converter.StringHttpMessageConverter"> 
        <property name="supportedMediaTypes" value="text/html;charset=utf-8"></property> 
      </bean> 
    </mvc:message-converters> 
  </mvc:annotation-driven> 

但是配置完后又有了新的問題

error:...cvc-complex-type.2.1: 元素 'mvc:annotation-driven' 必須不含字符或元素信息項 [子級], 因為該類型的內(nèi)容類型為空。

后來知道是 springMVC的XSD文件版本不對,換成springMVC 4.0的 XSD就可以了

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/beans  
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
            http://www.springframework.org/schema/context  
            http://www.springframework.org/schema/context/spring-context-3.1.xsd  
            http://www.springframework.org/schema/mvc  
            http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

然后就ok了

{"data":["資訊請購類","促銷類","管理類","暫支類","儲運類","資產(chǎn)類","資訊服務(wù)類","差旅管理類","采購類","人事考勤類"<br>,"財務(wù)類","客戶類","視拓類","客訴類","人事活動類","人事行政類","公文類","請款類","銷管類","營運業(yè)務(wù)類"],"status":true}
StringHttpMessageConverter 這個方法 有很多轉(zhuǎn)換作用,有時間可以多看看

以上這篇spring+mybatis 通過@ResponseBody返回結(jié)果中文亂碼的解決方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

庆安县| 章丘市| 贵德县| 和静县| 长子县| 龙岩市| 舟山市| 密山市| 湖南省| 廊坊市| 尤溪县| 桐城市| 车致| 青龙| 梧州市| 铜川市| 黄平县| 兴安县| 修水县| 平乡县| 芜湖县| 吉木萨尔县| 威信县| 汝城县| 静海县| 揭阳市| 靖西县| 通山县| 苗栗市| 水富县| 射阳县| 军事| 陕西省| 宁波市| 张掖市| 福海县| 乐业县| 清水县| 宁海县| 枣阳市| 井陉县|