可以使用 Spring MVC 的 @ResponseBody 注解将文件作为静态资源返回给客户端。在控制器方法上使用该注解并使用 ResourceLoader 接口获取文件即可。
代码示例:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
@Controller
public class FileController {
private final ResourceLoader resourceLoader;
@Autowired
public FileController(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
@GetMapping("/file")
@ResponseBody
最后
以上就是虚拟天空最近收集整理的关于通过 Spring 的 ResourceLoader 接口将文件作为静态资源返回给客户端。怎么使用的全部内容,更多相关通过内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复