首页 > 其他分享 >导出excel数据报错Could not find acceptable representation

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

时间:2022-09-23 11:12:05浏览次数:50  
标签:Could excel Controller json 报错 find

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

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

或者设置返回值为void


原文链接:https://blog.csdn.net/IntialJ/article/details/106462443

标签:Could,excel,Controller,json,报错,find
From: https://www.cnblogs.com/yjwfcs/p/16721991.html

相关文章