0
点赞
收藏
分享

微信扫一扫

SpringMvc: StreamResponseBody的用法


package cn.edu.tju.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

import java.io.IOException;
import java.io.OutputStream;

@RestController
public class DownloadController {
@GetMapping("/download")
public StreamingResponseBody handle() {
return new StreamingResponseBody() {
@Override
public void writeTo(OutputStream outputStream) throws IOException {
outputStream.write("this is a book".getBytes());
}
};
}
}


举报

相关推荐

0 条评论