springmvc ResponseEntity 下载文件损坏问题解决方法
生活随笔
收集整理的這篇文章主要介紹了
springmvc ResponseEntity 下载文件损坏问题解决方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
跟上貼https://blog.csdn.net/qq_36646591/article/details/81698614,這兩天做一個文件下載功能,基本上使用的就是springmvc的ResponseEntity來做的,問題是下載的文件總是提示【文件損壞】導致打不開,或者是成功下載了打開提示【文件內容損壞】,研究來研究去網上答案很多但是都不解決問題,唯一解決問題的就是這個帖子,地址如下:http://www.iteye.com/topic/1125784,作者解決問題的思路也很棒。
好了,不多說了,直接說說問題解決方法吧,主要就是配置文件里的順序:
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"><property name="messageConverters"><list><bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/><bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"><property name="supportedMediaTypes"><list><value>application/json;charset=UTF-8</value><value>text/json;charset=UTF-8</value><value>text/html;charset=UTF-8</value></list></property></bean><bean class="org.springframework.http.converter.StringHttpMessageConverter"><property name="supportedMediaTypes"><list><value>text/plain;charset=UTF-8</value></list></property></bean></list></property></bean>主要就是<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>要放在MappingJackson2HttpMessageConverter的前面,修改之后問題解決!
總結
以上是生活随笔為你收集整理的springmvc ResponseEntity 下载文件损坏问题解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle表空间缩减操作手册
- 下一篇: s3c2440移植MQTT