最简单的方法是使用
Resource。
@GetMapping(path = "/pdf", produces = "application/pdf")ResponseEntity<Resource> getPDF() { Resource pdfFile = ...; HttpHeaders headers = new HttpHeaders(); headers.setContentDispositionFormData(file.getName(), file.getName()); return ResponseEntity .ok().cacheControl(CacheControl.noCache()) .headers(headers).body(resource);}请注意,这里
DataBufferUtils有一些将
InputStreama
转换为a的有用方法
Flux<DataBuffer>,例如
DataBufferUtils#read()。但是处理a
Resource仍然更好。



