代码如下:
/**
* 下载案件excel模板
*
* @param res
* @throws IOException
*/
@RequestMapping("downTemplate")
public Object downTemplate(HttpServletResponse res, HttpServletRequest request) {
ResponseEntity<InputStreamResource> response = null;
try {
// 要下载的文件在项目中的路径(一般放在resource下的文件夹内)
String path = "/static/source/template/case_upload_model.xlsx";
String fileName = path.substring(path.lastIndexOf("/") + 1);
// 根据路径读取文件
ClassPathResource resource = new ClassPathResource(path);
File sourceFile = resource.getFile();
FileInputStream inputStream = new FileInputStream(sourceFile);
// 设置头 和 返回包体
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition",
"attachment; filename=" + fileName);
headers.add("