時間:2023-07-06 06:30:02 | 來源:網(wǎng)站運營
時間:2023-07-06 06:30:02 來源:網(wǎng)站運營
開發(fā)一個springboot+vue的項目【增加鈴聲制作的功能】:?大家好呀,我是小孟!參考的地址:https://github.com/Yin-Hongwei前面小伙伴說要學(xué)習(xí)spring+vue的項目,我們錄制了非常詳細的教程,視頻播放了突破了30w+,看來是真的香!
https://www.bilibili.com/video/BV15541177pE?spm_id_from=333.999.0.0
@RestControllerpublic class AdminController { @Autowired private AdminService adminService; /** * 判斷是否登錄成功 */ @RequestMapping(value = "/admin/login/status",method = RequestMethod.POST) public Object loginStatus(HttpServletRequest request, HttpSession session){ JSONObject jsonObject = new JSONObject(); String name = request.getParameter("name"); String password = request.getParameter("password"); boolean flag = adminService.verifyPassword(name,password); if(flag){ jsonObject.put(Consts.CODE,1); jsonObject.put(Consts.MSG,"登錄成功"); session.setAttribute(Consts.NAME,name); return jsonObject; } jsonObject.put(Consts.CODE,0); jsonObject.put(Consts.MSG,"用戶名或密碼錯誤"); return jsonObject; }}/** * 收藏控制類 */@RestController@RequestMapping("/collect")public class CollectController { @Autowired private CollectService CollectService; @Autowired private SongService songService; /** * 添加收藏 */ @RequestMapping(value = "/add",method = RequestMethod.POST) public Object addCollect(HttpServletRequest request){ JSONObject jsonObject = new JSONObject(); String userId = request.getParameter("userId"); //用戶id String type = request.getParameter("type"); //收藏類型(0歌曲1歌單) String songId = request.getParameter("songId"); //歌曲id if(songId==null||songId.equals("")){ jsonObject.put(Consts.CODE,0); jsonObject.put(Consts.MSG,"收藏歌曲為空"); return jsonObject; } if(CollectService.existSongId(Integer.parseInt(userId),Integer.parseInt(songId))){ boolean status = CollectService.deleteByUserIdSongId(Integer.parseInt(userId), Integer.parseInt(songId)); if (status) { jsonObject.put(Consts.CODE,2); jsonObject.put(Consts.MSG,"取消收藏"); } return jsonObject; } //保存到收藏的對象中 Collect Collect = new Collect(); Collect.setUserId(Integer.parseInt(userId)); Collect.setType(new Byte(type)); Collect.setSongId(Integer.parseInt(songId)); boolean flag = CollectService.insert(Collect); if(flag){ //保存成功 jsonObject.put(Consts.CODE,1); jsonObject.put(Consts.MSG,"收藏成功"); return jsonObject; } jsonObject.put(Consts.CODE,0); jsonObject.put(Consts.MSG,"收藏失敗"); return jsonObject; } /** * 刪除收藏 */ @RequestMapping(value = "/delete",method = RequestMethod.GET) public Object deleteCollect(HttpServletRequest request){ String userId = request.getParameter("userId"); //用戶id String songId = request.getParameter("songId"); //歌曲id boolean flag = CollectService.deleteByUserIdSongId(Integer.parseInt(userId),Integer.parseInt(songId)); return flag; } /** * 查詢所有收藏 */ @RequestMapping(value = "/allCollect",method = RequestMethod.GET) public Object allCollect(HttpServletRequest request){ return CollectService.allCollect(); } /** * 查詢某個用戶的收藏列表 */ @RequestMapping(value = "/collectOfUserId",method = RequestMethod.GET) public Object collectOfUserId(HttpServletRequest request){ String userId = request.getParameter("userId"); //用戶id return CollectService.collectOfUserId(Integer.parseInt(userId)); } /** * 獲取歌曲的收藏量 */ @RequestMapping(value = "/getCollectCount",method = RequestMethod.GET) public Object getCollectCount(@RequestParam("userId") Integer userId) { List<Collect> collectList = CollectService.getCollectCount(userId); for (Collect collect : collectList) { List<Song> song = songService.getSongId(collect.getSongId()); collect.setSongs(song); } return collectList; }/** * 歌曲管理controller */@RestController@RequestMapping("/song")public class SongController { @Autowired private SongService songService; /** * 添加歌曲 */ @RequestMapping(value = "/add",method = RequestMethod.POST) public Object addSong(HttpServletRequest request, @RequestParam("file")MultipartFile mpFile, @RequestParam("files")MultipartFile mvFile){ JSONObject jsonObject = new JSONObject(); //獲取前端傳來的參數(shù) String singerId = request.getParameter("singerId").trim(); //所屬歌手id String name = request.getParameter("name").trim(); //歌名 String introduction = request.getParameter("introduction").trim(); //簡介 String pic = "/img/songPic/tubiao.jpg"; //默認圖片 String lyric = request.getParameter("lyric").trim(); //歌詞 //上傳歌曲文件 if(mpFile.isEmpty()){ jsonObject.put(Consts.CODE,0); jsonObject.put(Consts.MSG,"歌曲上傳失敗"); return jsonObject; } //文件名=當(dāng)前時間到毫秒+原來的文件名 String fileName = System.currentTimeMillis()+mpFile.getOriginalFilename(); //文件路徑 String filePath = System.getProperty("user.dir")+System.getProperty("file.separator")+"song"; //如果文件路徑不存在,新增該路徑 File file1 = new File(filePath); if(!file1.exists()){ file1.mkdir(); } //實際的文件地址 File dest = new File(filePath+System.getProperty("file.separator")+fileName); //存儲到數(shù)據(jù)庫里的相對文件地址 String storeUrlPath = "/song/"+fileName; try { mpFile.transferTo(dest); Song song = new Song(); song.setSingerId(Integer.parseInt(singerId)); song.setName(name); song.setIntroduction(introduction); song.setPic(pic); song.setLyric(lyric); song.setUrl(storeUrlPath); if(!mvFile.isEmpty()){ //文件名=當(dāng)前時間到毫秒+原來的文件名 String fileNames = System.currentTimeMillis()+mvFile.getOriginalFilename(); //文件路徑 String filePaths = System.getProperty("user.dir")+System.getProperty("file.separator")+"mv"; //如果文件路徑不存在,新增該路徑 File file2 = new File(filePaths); if(!file2.exists()){ file2.mkdir(); } //實際的文件地址 File dests = new File(filePaths+System.getProperty("file.separator")+fileNames); mvFile.transferTo(dests); //存儲到數(shù)據(jù)庫里的相對文件地址 String storeUrlPaths = "/mv/"+fileNames; song.setMvurl(storeUrlPaths); } boolean flag = songService.insert(song); if(flag){ jsonObject.put(Consts.CODE,1); jsonObject.put(Consts.MSG,"保存成功"); jsonObject.put("avator",storeUrlPath); 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; } }** * 歌單的歌曲管理controller */@RestController@RequestMapping("/listSong")public class ListSongController { @Autowired private ListSongService listSongService; /** * 給歌單添加歌曲 */ @RequestMapping(value = "/add", method = RequestMethod.POST) public Object addListSong(HttpServletRequest request) { JSONObject jsonObject = new JSONObject(); //獲取前端傳來的參數(shù) String songId = request.getParameter("songId").trim(); //歌曲id Integer songListId = Integer.valueOf(request.getParameter("songListId").trim()); //歌單id List<ListSong> listSongs = listSongService.selectBySongId(songId); for (ListSong listSong : listSongs) { Integer id = listSong.getId(); ListSong songlist = listSongService.selectByPrimaryKey(id); if (songlist.getSongListId().equals(songListId)) { jsonObject.put(Consts.CODE, 0); jsonObject.put(Consts.MSG, "添加失敗,原因是:歌曲重復(fù)"); return jsonObject; } } ListSong listSong1 = new ListSong(); listSong1.setSongId(Integer.parseInt(songId)); listSong1.setSongListId(songListId); boolean flag = listSongService.insert(listSong1); if (flag) { jsonObject.put(Consts.CODE, 1); jsonObject.put(Consts.MSG, "保存成功"); return jsonObject; } else { jsonObject.put(Consts.CODE, 0); jsonObject.put(Consts.MSG, "保存失敗"); } return jsonObject; } /** * 根據(jù)歌單id查詢歌曲 */ @RequestMapping(value = "/detail", method = RequestMethod.GET) public Object detail(HttpServletRequest request) { String songListId = request.getParameter("songListId"); return listSongService.listSongOfSongListId(Integer.parseInt(songListId)); } /** * 刪除歌單里的歌曲 */ @RequestMapping(value = "/delete", method = RequestMethod.GET) public Object delete(HttpServletRequest request) { String songId = request.getParameter("songId").trim(); //歌曲id String songListId = request.getParameter("songListId").trim(); //歌單id boolean flag = listSongService.deleteBySongIdAndSongListId(Integer.parseInt(songId), Integer.parseInt(songListId)); return flag; }
? 好了,springboot+vue的音樂項目整理結(jié)束,小伙伴們點贊、收藏、評論,一鍵三連走起呀,下期見~~關(guān)鍵詞:功能,增加,項目
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。