ResourceResponseEntity 创建的命名文件

Naming file created by ResourceResponseEntity

在我的 REST 应用程序中,我收到一个请求,它通过
向用户返回一个 excel 文件 return new ResourceResponseEntity(new ByteArrayResource(content) 其中 contentbyte[]

问题

问题是结果文件总是以与请求方法名称相同的方式命名,这很糟糕,因为很难在该文件中找到某些信息

问题

所以问题是我能否使用我现在正在使用的方式以某种方式控制文件命名过程,感谢任何帮助

您可以创建 HttpHeaders object 和 Content-Disposition header 以及

HttpHeaders header = new HttpHeaders();
header.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename;

然后将此 HttpHeaders object 添加到您的 Resource ResponseEntity 中,例如 .headers(header).