img标签
<img style="width:100%;height:100%;" class="minImg" src="satellite/img?id=b9d1c1d8-f191-11e9-a407-80a589861ae2">
java部分
// 获取图片信息
@RequestMapping(value = "/img",method = RequestMethod.GET)
public String img(HttpServletRequest request, HttpServletResponse response, HttpSession session){
ServletOutputStream outputStream = null;
FileInputStream inputStream = null;
try {
String id = request.getParameter("id");
if(ToolsUtil.isEmpty(id)) return null;
Satellite satellite = liveService.getSatelliteById(id);
if(satellite == null) return null;
String path = satellite.getPngfilepath();
File file = new File(path);
if(!file.exists()) return null;
inputStream = new FileInputStream(file);
response.setContentType("multipart/form-data");
outputStream = response.getOutputStream();
//读取文件流
int len = 0;
byte[] buffer = new byte[1024 * 10];
while ((len = inputStream.read(buffer)) != -1){
outputStream.write(buffer,0,len);
}
outputStream.flush();
outputStream.close();
inputStream.close();
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
然后,图片就可以正常显示啦~