SpringBoot显示图片

SpringBoot显示图片其实很简单,代码如下:

1
2
3
4
5
6
7
8
@RequestMapping("/getimage")
public void getimage(HttpServletResponse response) throws IOException{
BufferedImage image = ImageIO.read(Files.newInputStream(Paths.get("D:\\laiscdata\\1.png")));
response.setHeader("Cache-Control", "no-store,no-cache");
response.setContentType("image/jpeg");
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image,"jpg",out);
}