【Springboot】项目下载Resource目录下Excel模板打开报错
1.需求背景
之前的Excel模板是放在服务器上,通过Ng配置直接下载.后由于安全部门扫描说不合规.所以为了方便,就将这些模板放在项目Resource目录下.再通过接口来下载.
2.完整接口代码
@GetMapping("/template/downLoad")
@ApiOperation(value = "模板文件下载", produces = "application/octet-stream")
@ApiImplicitParam(name = "fileName", value = "附件名称", paramType = "query", dataType = "String")
public void downloadTemplate(@RequestParam("fileName") String fileName, HttpServletResponse response) {
InputStream inputStream = null;
OutputStream outputStream = null;
try {
Resource resource = new DefaultResourceLoader().getResource("classpath:template/" + fileName);
boolean exists = resource.exists();
if