直接從本地拿取圖片給前端顯示货矮,直接給前端流數(shù)據(jù):
public static void getPhoto(HttpServletResponse response, String imgUrl) throws Exception {
String path = "你的路徑" + imgUrl;
File file = new File(path);
FileInputStream fis;
fis = new FileInputStream(file);
long size = file.length();
byte[] temp = new byte[(int) size];
fis.read(temp, 0, (int) size);
fis.close();
byte[] data = temp;
response.setContentType("image/png");
OutputStream out = response.getOutputStream();
out.write(data);
out.flush();
out.close();
}