后端代码
@ApiOperation("根据歌曲id下载")
@GetMapping("/download")
public CommonResult download(Integer id, HttpServletResponse response){
//根据id查询歌曲
SongDTO song = songService.getSongById(id);
//获取数据库中歌曲路径
String url = song.getSongUrl();
//获取文件名
String fileName = url.substring(url.lastIndexOf("/")+1,url.length());
//拼接文件路径
String path = songRealPath + fileName;
File file = new File(path);
if(file.exists()){
//二进制附件都应该被叫做application/octet- stream