首页 > 编程语言 > 详细

SpringBoot导出excel数据报错Could not find acceptable representation

时间:2020-02-20 19:30:53      阅读:1820      评论:0      收藏:0      [点我收藏+]

转自:https://blog.csdn.net/mate_ge/article/details/93518286?utm_source=distribute.pc_relevant.none-task

今天在实现响应输出流下载模板文件时,虽然功能正常,但是后台一直报错:

org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

截图

技术分享图片

 

 

在导出excel文件时,返回的数据时文件流的格式,写入到response.getOutputStream()中的,返回的数据前端下载是没有问题的,但是后端就是有报错,最后在仔细检查才发现,是因为我在Controller类上使用了注解@RestController,该注解会把该Controller下所有的请求返回的数据格式化为json,但是数据导出返回的格式是文件流,所以这里就报错了。最后吧@RestController换回@Controller就好了,还得给该Controller下所有的请求,需要将结果转化为json的请求,加上@ResponseBody注解,注明返回结果需要格式化为json格式;

SpringBoot导出excel数据报错Could not find acceptable representation

原文:https://www.cnblogs.com/qingshan-tang/p/12336524.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!