您的位置:首页 > 编程语言 > Java开发

springmvc ResponseEntity 下载文件损坏问题解决方法

2017-12-18 14:45 956 查看
这两天做一个文件下载功能,基本上使用的就是springmvc的ResponseEntity来做的,这块代码就不贴了,网上大把大把的,问题是下载的文件总是提示【文件损坏】导致打不开,word,excel,zip文件统统打不开,研究来研究去网上答案很多但是都不解决问题,唯一解决问题的就是这个帖子,地址如下: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>

红色部分要放在MappingJackson2HttpMessageConverter的前面,修改之后问题解决!

原文链接:http://blog.csdn.net/u013555226/article/details/77026068
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: