1、图片下载
@RequestMapping("/downPicture")
public void downPicture(HttpServletRequest request,HttpServletResponse response){
ByteArrayOutputStream out = new ByteArrayOutputStream();
try{
String imagePath = "f://test.png";//无斜杠结尾
File file = new File(imagePath);
FileInputStream in = new FileInputStream(file);
byte[] b = new byte[1024];
int i = 0;
while ((i = in.read(b)) != -1) {
out.write(b, 0, b.length);
}
in.close();
String fileName = "test.png";
ServletOutputStream sos = response.getOutputStream();
response.setContentType("application/vnd.ms-excel");
response.setContentLength(out.size());
response.setHeader("Content-disposition", "attachment;filename="+fileName);
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "max-age=0");
sos.write(out.toByteArray());
out.flush();
out.close();
sos.flush();
}catch(Exception e){
logger.error("downPicture:下载图片异常:"+e.getMessage(), e);
}
}
2、导出Excel为压缩包
@SuppressWarnings("unchecked")
@RequestMapping("/exportTacList")
public void exportTacLi