1. 程式人生 > >springmvc返回檔案的正確寫法(下載檔案)

springmvc返回檔案的正確寫法(下載檔案)

@RequestMapping("/test")
public ResponseEntity<byte[]> test(HttpServletRequest request) throws Exception {
    HttpHeaders headers = new HttpHeaders();
headers.setContentDispositionFormData("attachment", "publicKey");
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return new ResponseEntity<>(
"test".getBytes(), headers, HttpStatus.CREATED);}