标签:mvc 文件名 rda code return dia file ati null
方法1 springMVC的ResponEntity<byte[]>
前台:<a>链接请求
后台:返回ResponEntity<byte[]>
public ResponseEntity<byte[]> download(String downloadPath,String filename){
//downloadPath:文件的路径,到文件名 //filename:导出后显示的文件名 File file=new File(downlaodpath);
HttpHeads heads=new HttpHeads();
if(filename==null||"".equals(filename)){
filename=new String(file.getName().getBytes("UTF-8"),"iso-8859-1")//为了解决中文乱码
}else{
filename=new String(file.getBytes("UTF-8"),"iso-8859-1")//为了解决中文乱码
}
heads.setContentDispositionForData("attachment",filename);
heads.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return new ResponseEntity<byte[]>(FileUtis.readFileToByTeArray(file),heads,HttpStatus.CREATED);
}
方法2 输出流
标签:mvc 文件名 rda code return dia file ati null
原文地址:https://www.cnblogs.com/xiandong/p/9934901.html