@RequestMapping(value = "/downloadFile", method = RequestMethod.GET) public void downloadFile(HttpServletResponse response,@RequestParam String filePath){ try { String group= filePath.substring(0,filePath.indexOf("/")); String path= filePath.substring(filePath.indexOf("/")+1,filePath.length()); ServletOutputStream toClient = response.getOutputStream(); response.setContentType("application/octet-stream"); response.reset(); byte[] bytes = fastDFSClientUtil.downloadFile(group,path); toClient.write(bytes); toClient.flush(); toClient.close(); } catch (Exception e) { e.printStackTrace(); } }
修改返回值类型为 void 就解决这个异常