@PostMapping("/stream")
public ResponseEntity<StreamingResponseBody> stream() {
StreamingResponseBody stream = out -> {
for (int i = 0; i < 3; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
out.write(("This is line " + i + "\n").getBytes());
out.flush();
}
};
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(stream);
}
标签:返回,springboot,stream,流式,ResponseEntity,out
From: https://www.cnblogs.com/rise0111/p/17465518.html