//下载
@RequestMapping(value="/downLoad")
@ResponseBody
public ResponseEntity<byte[]> downLoad(HttpServletRequest req,Integer id){
String name = uploadingReportsService.selectName(id);
if (name != null) {
String[] split = name.split("/");
String path=req.getSession().getServletContext().getRealPath("/uploadFile");
File file = new File(path, name);
if (file.exists()) {
try {
String dfileName = new String(split[1].getBytes("gb2312"), "iso8859-1");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", dfileName);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return null;
}
spring mvc 实现下载
最新推荐文章于 2024-09-15 19:46:31 发布