内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

springMVC@response中文亂碼解決-創(chuàng)新互聯(lián)

新人學(xué)習(xí)springMVC開發(fā)框架,用到ajax 通過 @response 來獲取返回值。

成都創(chuàng)新互聯(lián)公司一直秉承“誠信做人,踏實做事”的原則,不欺瞞客戶,是我們最起碼的底線! 以服務(wù)為基礎(chǔ),以質(zhì)量求生存,以技術(shù)求發(fā)展,成交一個客戶多一個朋友!為您提供網(wǎng)站建設(shè)、網(wǎng)站設(shè)計、成都網(wǎng)頁設(shè)計、重慶小程序開發(fā)公司、成都網(wǎng)站開發(fā)、成都網(wǎng)站制作、成都軟件開發(fā)、app開發(fā)定制是成都本地專業(yè)的網(wǎng)站建設(shè)和網(wǎng)站設(shè)計公司,等你一起來見證!

不得不說 @response的功能很強大,可以直接將返回類打包成json格式省卻了很多事,

但是如果返回值是String類型的話,就會出現(xiàn)中文亂碼問題,自己試著做了一些調(diào)整,并在網(wǎng)上查看了許多方法,在這里總結(jié)一下。

1.添加注解   produces = {"application/json;charset=UTF-8"}

@RequestMapping(value = "/method.do", produces = {"application/json;charset=UTF-8"})

適用于少量的,每寫一個方法就得添加一次,不適合統(tǒng)一處理。

2.添加配置   在springMVC-*.xml里面進(jìn)行String編碼配置,如下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" 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/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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-3.1.xsd">
    <!-- utf-8編碼 -->
    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <constructor-arg value="UTF-8" />
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
    <!-- <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name="supportedMediaTypes" value="text/plain;charset=UTF-8" />
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven> -->
 。。。。。
</beans>

如果可以看org.springframework.http.converter.StringHttpMessageConverter這個類的源碼的話就會發(fā)現(xiàn)其默認(rèn)的編碼方式為  "ISO-8859-1",

這個應(yīng)該是造成我們中文亂碼的主要原因。

在這里不能不吐槽一下,好多老外寫的jar包都會出現(xiàn)中文亂碼問題,究其主要原因就是人家不用中文。。。故肯定會選擇內(nèi)存占用小的"ISO-8859-1",

啥時候才能大家都統(tǒng)一使用utf-8呀。。

當(dāng)前文章:springMVC@response中文亂碼解決-創(chuàng)新互聯(lián)
網(wǎng)址分享:http://www.rwnh.cn/article38/icspp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、做網(wǎng)站、動態(tài)網(wǎng)站網(wǎng)站維護(hù)、網(wǎng)站排名、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名
历史| 仙游县| 绍兴市| 苏尼特左旗| SHOW| 从化市| 衡东县| 西昌市| 张家川| 阿拉善右旗| 永州市| 新龙县| 滨海县| 盖州市| 通河县| 齐齐哈尔市| 阳东县| 崇仁县| 小金县| 岳阳县| 时尚| 开江县| 嘉义市| 庆云县| 贵阳市| 忻城县| 裕民县| 伊吾县| 连城县| 贺兰县| 泉州市| 磴口县| 民权县| 黎平县| 屯留县| 临高县| 阿鲁科尔沁旗| 恩施市| 南开区| 伽师县| 资源县|