后台如何将图片的byte[]转成流传给前端展示

这里用springMVC做个例子,前端请求以下方法时,直接返回一张图片

@RequestMapping("/showPhoto")
public void showPhoto(String photoID, HttpServletResponse response) {
	OutputStream outputStream = null;
	try {
		byte[] photoByte = photo.getPhoto(photoID);
		outputStream = response.getOutputStream();
		outputStream.write(photoByte);
		outputStream.flush();
	} catch (Exception e) {
		logger.error("error", e);
	} finally {
		try {
			outputStream.close();
		} catch (IOException e) {
			logger.error("error", e);
		}
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_44919928/article/details/89410010