前端 // 就是获取图片的存储路径,让图片标签的src值指向一个后台写流的方法function showImg(img) { let url = img.url let path = '/uploadFileFile/getBytesByAbsolutePath?imgPath=' + url $('img').attr('src', path)} 后端 /** * @Description: 根据图片的绝对路径返回字节流 */@RequestMapping(value = "/getBytesByAbsolutePath")@ResponseBodypublic void getBytesByAbsolutePath(HttpServletRequest request, HttpServletResponse response) throws Exception{ String imgPath = request.getParameter("imgPath"); File file = new File(imgPath); if(file.exists()){ InputStream is = new FileInputStream(file); byte[] bytes = new byte[is.available()]; is.read(bytes); is.close(); OutputStream os = response.getOutputStream(); response.setContentType("image/*"); os.write(bytes); os.close(); }else { System.out.println("图片不存在"); }}