后端代码:
@RequestMapping(value = “read”)
public void index(Model model, HttpServletRequest req,
HttpServletResponse resp, String attachmentId) {
byte [] bytes = null;
ServletOutputStream sos =null;// 将图像输出到Servlet输出流中。
try {
GetImageRes getImageRes = acctManager.getImageBytes(attachmentId);
bytes = getImageRes.getFilebyte();
ByteArrayInputStream in = new ByteArrayInputStream(bytes); //将b作为输入流;
BufferedImage image = ImageIO.read(in);
resp.setHeader(“Pragma”, “no-cache”);
resp.setHeader(“Cache-Control”, “no-cache”);
resp.setDateHeader(“Expires”, 0);
sos = resp.getOutputStream();// 将图像输出到Servlet输出流中。
ImageIO.write(image, “jpeg”, sos);
} catch (IOException e) {
e.printStackTrace()