1、前端可使用a标签导出:
@GetMapping("/downloadAddCardFtl")
@ApiOperation("下载导卡OR分配卡模板")
public void downloadFtl(HttpServletResponse response) {
try {
//获取要下载的模板名称
String fileName = "导出模板.xls";
// 设置要下载的文件的名称
response.setHeader("Content-disposition", "attachment;filename=aaaa" + URLEncoder.encode(fileName, "UTF-8"));
// 通知客服文件的MIME类型
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
// 获取文件的路径
String path = "https://img.com/exportFile/tenant/20200407/ad629c25781f615e287c3e4c7bc570c5/exportTenant_20200407192206496.xlsx";
System.out.println(path);
URL url = new URL(path);
InputStream input = url.openStream();
//FileInputStream input = new FileInputStream(path);
OutputStream out = response.getOutputStream();
byte[] b = new byte[1024];
int len;
while ((len = input.read(b)) != -1) {
out.write(b, 0, len);
}
input.close();
} catch (Exception e) {
System.out.println("yichang!");
}
}
2、java后端