这里用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);
}
}
}
版权声明:本文为weixin_44919928原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。