国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
spring boot 亂碼解決匯總
  這幾天在工作中新使用springboot 然后遇到了亂碼問(wèn)題 springboot 的配置文件方式和之前的srping mvc 有很大不同就讓我很是困惑,先講解我們開(kāi)始使用的解決方案:
在application.properties 中增加
spring.http.encoding.force=truespring.http.encoding.charset=UTF-8spring.http.encoding.enabled=trueserver.tomcat.uri-encoding=UTF-8

用來(lái)解決亂碼問(wèn)題
然后發(fā)現(xiàn)在攔截器中返回的中文已經(jīng)不亂碼了。
在后續(xù)測(cè)試中發(fā)現(xiàn)controller中返回的數(shù)據(jù)依舊亂碼,于是在

@RequestMapping中增加produces="text/plain;charset=UTF-8"


但是總覺(jué)得要限定了請(qǐng)求的數(shù)據(jù)類型,所以繼續(xù)研究,然后在查找的時(shí)候發(fā)現(xiàn)了HttpMessageConverter類 ,在其中的方法

protected Long getContentLength(String str, MediaType contentType) {    Charset charset = this.getContentTypeCharset(contentType);    try {        return Long.valueOf((long)str.getBytes(charset.name()).length);    } catch (UnsupportedEncodingException var5) {        throw new IllegalStateException(var5);    }}

private Charset getContentTypeCharset(MediaType contentType) {    return contentType != null && contentType.getCharset() != null?contentType.getCharset():this.getDefaultCharset();}
中發(fā)現(xiàn) getContentTypeCharset的MediaType是入?yún)⒌臄?shù)據(jù) 里面的utf-8然后在getContentLength的MediaType 的編碼是ISO-8859-1 看了下這個(gè)類中

ublic static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");
所以下面的主要工作就是修改這個(gè)默認(rèn)編碼

然后找到了下面兩篇文章

http://stackoverflow.com/questions/20935969/make-responsebody-annotated-spring-boot-mvc-controller-methods-return-utf-8

http://stackoverflow.com/questions/27606769/how-to-overwrite-stringhttpmessageconverter-default-charset-to-use-utf8-in-sprin

在國(guó)際有人的支援下在WebAppConfig中增加了

@Beanpublic HttpMessageConverter<String> responseBodyConverter() {    StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));    return converter;}@Overridepublic void configureMessageConverters(List<HttpMessageConverter<?>> converters) {    super.configureMessageConverters(converters);    converters.add(responseBodyConverter());}

完美解決了亂碼問(wèn)題





本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Spring3 MVC使用@ResponseBody的亂碼問(wèn)題及解決辦法
No HttpMessageConverter for java.util.LinkedHashMap and content type \"application/x-www-form-urlencoded;charset=UTF-8\
jQuery Ajax中文亂碼問(wèn)題?
JSP亂碼的解決
SSM框架——SpringMVC中使用@ResponseBody注解返回值,Ajax取得中文亂碼解決方法
SpringMVC源碼總結(jié)(四)由StringHttpMessageConverter引出的客戶端服務(wù)器端之間的亂碼過(guò)程分析
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服