Springboot Download file

@RequestMapping(value = "/downloadSvt")

public ResponseEntity<FileSystemResource> export() {

HttpHeaders headers = new HttpHeaders();

headers.add("Cache-Control", "no-cache, no-store, must-revalidate");

headers.add("Content-Disposition", "attachment; filename=client.js");

headers.add("Pragma", "no-cache");

headers.add("Expires", "0");

File file = new File("./client.js");

return ResponseEntity.ok().headers(headers).contentLength(file.length())

.contentType(MediaType.parseMediaType("application/octet-stream")).body(new FileSystemResource(file));

}

原文地址:https://www.cnblogs.com/wblade/p/8595989.html