<a href="${pageContext.request.contextPath}/fileDowland.do">click me to dowland</a>
@RequestMapping("/fileDowland.do")
public ResponseEntity<byte[]> fileDowland() throws IOException{
//指定下载文件
File file=new File("C:/Users/Administrator/Downloads/1.jpg");
FileInputStream is = new FileInputStream(file);
//通过字节数组保存文件
byte[] body=new byte[is.available()];
is.read(body);
//获取文件名
String name = file.getName();
//转换文件名格式
String dowlandFilename = new String(name.getBytes("UTF-8"),"ISO-8859-1");
//设置文件头
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Content-Disposition", "attachment;filename="+dowlandFilename);
HttpStatus status = HttpStatus.OK;
ResponseEntity<byte[]> responseEntity = new ResponseEntity<>(body, httpHeaders,status);
return responseEntity;
}