From 2a7b85009002438f6a5b020cb61ef84409b06870 Mon Sep 17 00:00:00 2001 From: duhang Date: Sun, 10 Sep 2023 15:53:30 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=A7=A3=E5=86=B3=E4=BF=AE=E6=94=B9=E5=8D=95?= =?UTF-8?q?=E4=B8=AA=E6=AD=8C=E6=9B=B2=E4=BF=A1=E6=81=AF=E4=BC=9A=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E4=BF=AE=E6=94=B9=E6=89=80=E6=9C=89=E6=AD=8C=E6=9B=B2?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84bug;=202.=E5=9C=A8SongController?= =?UTF-8?q?=E7=B1=BB=E4=B8=AD=E6=96=B0=E5=A2=9E=E6=9B=B4=E6=96=B0=E6=AD=8C?= =?UTF-8?q?=E6=9B=B2=E6=96=87=E4=BB=B6=E7=9A=84=E6=96=B9=E6=B3=95;=203.?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=97=A0=E6=B3=95=E6=B7=BB=E5=8A=A0=E6=AD=8C?= =?UTF-8?q?=E6=89=8B=E7=9A=84bug,=E5=9C=A8Singer=E7=B1=BB=E7=9A=84id?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=B7=BB=E5=8A=A0@TableId=E6=B3=A8=E8=A7=A3;?= =?UTF-8?q?=204.=E8=A7=A3=E5=86=B3=E5=89=8D=E7=AB=AF=E6=AD=8C=E6=9B=B2?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0=E6=AD=8C=E6=9B=B2=E6=97=B6?= =?UTF-8?q?=E5=80=99=EF=BC=8C=E5=9C=A8=E8=BE=93=E5=85=A5=E6=A1=86=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=B2=A1=E6=9C=89=E6=98=BE=E7=A4=BA=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../music-manage/src/pages/SongPage.vue | 768 +++++++++--------- .../music/controller/SongController.java | 57 +- .../springclimb/music/entity/Singer.java | 5 + 3 files changed, 459 insertions(+), 371 deletions(-) diff --git a/music-manager/music-manage/src/pages/SongPage.vue b/music-manager/music-manage/src/pages/SongPage.vue index 7d3f0ab..beaa558 100644 --- a/music-manager/music-manage/src/pages/SongPage.vue +++ b/music-manager/music-manage/src/pages/SongPage.vue @@ -1,134 +1,132 @@ \ No newline at end of file +.icon { + width: 2em; + height: 2em; + color: white; + fill: currentColor; + overflow: hidden; +} +.crumbs{ + margin: 20px; +} + diff --git a/music-server/src/main/java/com/study/springclimb/music/controller/SongController.java b/music-server/src/main/java/com/study/springclimb/music/controller/SongController.java index c9a6449..0b8191f 100644 --- a/music-server/src/main/java/com/study/springclimb/music/controller/SongController.java +++ b/music-server/src/main/java/com/study/springclimb/music/controller/SongController.java @@ -7,10 +7,7 @@ import com.study.springclimb.music.entity.Song; import com.study.springclimb.music.service.SongService; import com.study.springclimb.music.utils.Consts; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.File; @@ -95,7 +92,7 @@ public class SongController { @RequestMapping(value = "/update", method = RequestMethod.POST) public Object updateSong(Song song) { JSONObject jsonObject = new JSONObject(); - boolean flag = songService.update(song, null); + boolean flag = songService.updateById(song); if (flag) { jsonObject.put(Consts.CODE, 1); jsonObject.put(Consts.MSG, "修改成功"); @@ -201,4 +198,54 @@ public class SongController { public Object allSong() { return songService.list(null); } + + /** + * 更新歌曲文件 + */ + @RequestMapping(value = "/updateSongUrl", method = RequestMethod.POST) + public Object updateSongUrl(@RequestParam("file") MultipartFile avatorFile, @RequestParam("id") int id) { + JSONObject jsonObject = new JSONObject(); + //如果文件是空的,直接返回 + if (avatorFile.isEmpty()) { + jsonObject.put(Consts.CODE, 0); + jsonObject.put(Consts.MSG, "文件上传失败"); + return jsonObject; + } + //文件名=当前时间到毫秒+原来的文件名 + String fileName = System.currentTimeMillis() + avatorFile.getOriginalFilename(); + //文件路径 + String filePath = System.getProperty("user.dir") + System.getProperty("file.separator") + "song"; + System.out.println("filePath is"+filePath); + //如果文件路径不存在,新增该路径 + File file1 = new File(filePath); + if (!file1.exists()) { + file1.mkdir(); + } + //实际的文件地址 + File dest = new File(filePath + System.getProperty("file.separator") + fileName); + //存储到数据库里的相对文件地址 + String storeAvatorPath = "/song/" + fileName; + try { + avatorFile.transferTo(dest);//上传 + Song song = new Song(); + song.setId(id); + song.setUrl(storeAvatorPath); + boolean flag = songService.updateById(song); + if (flag) { + jsonObject.put(Consts.CODE, 1); + jsonObject.put(Consts.MSG, "上传成功"); + jsonObject.put("song", storeAvatorPath); + return jsonObject; + } + jsonObject.put(Consts.CODE, 0); + jsonObject.put(Consts.MSG, "上传失败"); + return jsonObject; + } catch (IOException e) { + jsonObject.put(Consts.CODE, 0); + jsonObject.put(Consts.MSG, "上传失败" + e.getMessage()); + } finally { + return jsonObject; + } + } + } diff --git a/music-server/src/main/java/com/study/springclimb/music/entity/Singer.java b/music-server/src/main/java/com/study/springclimb/music/entity/Singer.java index 57d4275..de1e28d 100644 --- a/music-server/src/main/java/com/study/springclimb/music/entity/Singer.java +++ b/music-server/src/main/java/com/study/springclimb/music/entity/Singer.java @@ -1,5 +1,9 @@ package com.study.springclimb.music.entity; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.experimental.Accessors; + import java.util.Date; import java.io.Serializable; @@ -14,6 +18,7 @@ public class Singer implements Serializable { /** * 主键 */ + @TableId(value = "id",type = IdType.AUTO) private Integer id; /** * 姓名 -- Gitee