Skip to content

Instantly share code, notes, and snippets.

@codethereforam
Created February 27, 2024 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codethereforam/3029c2dbd10cd3b416a5ddd733b03817 to your computer and use it in GitHub Desktop.
Save codethereforam/3029c2dbd10cd3b416a5ddd733b03817 to your computer and use it in GitHub Desktop.
Spring导出文件
private ResponseEntity<byte[]> getExportResponse(String fileName, String exportContent) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", URLEncoder.encode(fileName, StandardCharsets.UTF_8));
return new ResponseEntity<>(exportContent.getBytes(StandardCharsets.UTF_8), headers, HttpStatus.OK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment