java
@RequestMapping("/test")
public void test(HttpServletResponse response) {
response.setCharacterEncoding("utf-8");
response.setContentType("text/plain");
response.setBufferSize(50);
try (PrintWriter printWriter = response.getWriter()) {
for (int i = 0; i < 100; i++) {
Thread.sleep(300);
printWriter.println(StrUtil.fillAfter("xxx",' ', 50));
printWriter.flush();
}
} catch (Exception e) {
log.error("syncAlc", e);
}
}
这里的关键就在于设置BufferSize,并且在输出后调用flush()方法。