业务场景:

导出excel、pdf文件后台报异常,但是文件可以正常导出和查看。

解决办法:

controller层返回值改为void

过程:

起因是导出excel文件,发现下载的excel文件无法正常打开,总是提示文件损坏,需要修复,于是在代码中加入了以下代码

//2007版本excel导出
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

文件可以正常打开了,内容也没问题,但是发现后台报错

exception [No converter for [class java.util.HashMap] with preset Content-Type 'vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8']

最后请教他人解决:controller层返回值改为void

@GetMapping("/exportExcel")
public void exportPdf(HttpServletRequest request, HttpServletResponse response){
	//导出实现
}
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐