文章目錄
- 在線音樂系統
- 一、項目演示
- 二、項目介紹
- 三、部分功能截圖
- 四、部分代碼展示
- 五、底部獲取項目(9.9¥帶走)
在線音樂系統
一、項目演示
音樂網站
二、項目介紹
基于springboot+vue的前后端分離在線音樂系統
登錄角色 : 用戶、管理員
用戶:歌單分類分頁界面,歌手分類分頁界面,我的音樂查看收藏歌曲,搜索音樂,可根據歌手、歌曲、歌單名進行搜索;頭像修改、用戶信息修改,歌曲播放,進度條拉伸,歌詞加載,歌曲收藏,歌曲下載,登錄、注冊等
管理員:系統首頁展示統計數據,用戶管理,歌手管理,歌曲管理(修改音源,歌詞,后臺評論),上傳音樂
語言:java
前端技術:vue、element-ui、echarts
后端技術:springboot、mybatisplus
數據庫:MySQL
三、部分功能截圖
四、部分代碼展示
package com.rabbiter.music.controller;import com.alibaba.fastjson.JSONObject;
import com.rabbiter.music.pojo.Collect;
import com.rabbiter.music.service.CollectService;
import com.rabbiter.music.utils.Consts;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.RestController;
import javax.servlet.http.HttpServletRequest;/*** 收藏控制類*/
@RestController
@RequestMapping("/collect")
@Api(tags = "收藏")
public class CollectController {@Autowiredprivate CollectService CollectService;/*** 添加收藏*/@ApiOperation(value = "添加收藏")@RequestMapping(value = "/add",method = RequestMethod.POST)public Object addCollect(HttpServletRequest request){JSONObject jsonObject = new JSONObject();String userId = request.getParameter("userId"); //用戶idString type = request.getParameter("type"); //收藏類型(0歌曲1歌單)String songId = request.getParameter("songId"); //歌曲idif(songId==null||songId.equals("")){jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"收藏歌曲為空");return jsonObject;}if(CollectService.existSongId(Integer.parseInt(userId),Integer.parseInt(songId))){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;}/*** 刪除收藏*/@ApiOperation(value = "取消收藏")@RequestMapping(value = "/delete",method = RequestMethod.GET)public Object deleteCollect(HttpServletRequest request){String userId = request.getParameter("userId"); //用戶idString songId = request.getParameter("songId"); //歌曲idboolean flag = CollectService.deleteByUserIdSongId(Integer.parseInt(userId),Integer.parseInt(songId));return flag;}/*** 查詢所有收藏*/@ApiOperation(value = "查看所有收藏")@RequestMapping(value = "/allCollect",method = RequestMethod.GET)public Object allCollect(HttpServletRequest request){return CollectService.allCollect();}/*** 查詢某個用戶的收藏列表*/@ApiOperation(value = "用戶的收藏列表")@RequestMapping(value = "/collectOfUserId",method = RequestMethod.GET)public Object collectOfUserId(HttpServletRequest request){String userId = request.getParameter("userId"); //用戶idreturn CollectService.collectOfUserId(Integer.parseInt(userId));}}
package com.rabbiter.music.controller;import com.alibaba.fastjson.JSONObject;
import com.rabbiter.music.pojo.Comment;
import com.rabbiter.music.service.CommentService;
import com.rabbiter.music.utils.Consts;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.RestController;
import javax.servlet.http.HttpServletRequest;/*** 評論控制類*/
@Api(tags = "評論")
@RestController
@RequestMapping("/comment")
public class CommentController {@Autowiredprivate CommentService commentService;/*** 添加評論*/@ApiOperation(value = "添加評論")@RequestMapping(value = "/add",method = RequestMethod.POST)public Object addComment(HttpServletRequest request){JSONObject jsonObject = new JSONObject();String userId = request.getParameter("userId"); //用戶idString type = request.getParameter("type"); //評論類型(0歌曲1歌單)String songId = request.getParameter("songId"); //歌曲idString songListId = request.getParameter("songListId"); //歌單idString content = request.getParameter("content").trim(); //評論內容//保存到評論的對象中Comment comment = new Comment();comment.setUserId(Integer.parseInt(userId));comment.setType(new Byte(type));if(new Byte(type) ==0){comment.setSongId(Integer.parseInt(songId));}else{comment.setSongListId(Integer.parseInt(songListId));}comment.setContent(content);boolean flag = commentService.insert(comment);if(flag){ //保存成功jsonObject.put(Consts.CODE,1);jsonObject.put(Consts.MSG,"評論成功");return jsonObject;}jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"評論失敗");return jsonObject;}/*** 修改評論*/@ApiOperation(value = "修改評論")@RequestMapping(value = "/update",method = RequestMethod.POST)public Object updateComment(HttpServletRequest request){JSONObject jsonObject = new JSONObject();String id = request.getParameter("id").trim(); //主鍵String userId = request.getParameter("userId").trim(); //用戶idString type = request.getParameter("type").trim(); //評論類型(0歌曲1歌單)String songId = request.getParameter("songId").trim(); //歌曲idString songListId = request.getParameter("songListId").trim(); //歌單idString content = request.getParameter("content").trim(); //評論內容//保存到評論的對象中Comment comment = new Comment();comment.setId(Integer.parseInt(id));comment.setUserId(Integer.parseInt(userId));comment.setType(new Byte(type));if(songId!=null&&songId.equals("")){songId = null;}else {comment.setSongId(Integer.parseInt(songId));}if(songListId!=null&&songListId.equals("")){songListId = null;}else {comment.setSongListId(Integer.parseInt(songListId));}comment.setContent(content);boolean flag = commentService.update(comment);if(flag){ //保存成功jsonObject.put(Consts.CODE,1);jsonObject.put(Consts.MSG,"修改成功");return jsonObject;}jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"修改失敗");return jsonObject;}/*** 刪除評論*/@ApiOperation(value = "刪除評論")@RequestMapping(value = "/delete",method = RequestMethod.GET)public Object deleteComment(HttpServletRequest request){String id = request.getParameter("id").trim(); //主鍵boolean flag = commentService.delete(Integer.parseInt(id));return flag;}/*** 根據主鍵查詢整個對象*/@ApiOperation(value = "根據主鍵查詢整個對象")@RequestMapping(value = "/selectByPrimaryKey",method = RequestMethod.GET)public Object selectByPrimaryKey(HttpServletRequest request){String id = request.getParameter("id").trim(); //主鍵return commentService.selectByPrimaryKey(Integer.parseInt(id));}/*** 查詢所有評論*/@ApiOperation(value = "查詢所有評論")@RequestMapping(value = "/allComment",method = RequestMethod.GET)public Object allComment(HttpServletRequest request){return commentService.allComment();}/*** 查詢某個歌曲下的所有評論*/@ApiOperation(value = "查詢某個歌曲下的所有評論")@RequestMapping(value = "/commentOfSongId",method = RequestMethod.GET)public Object commentOfSongId(HttpServletRequest request){String songId = request.getParameter("songId"); //歌曲idreturn commentService.commentOfSongId(Integer.parseInt(songId));}/*** 查詢某個歌單下的所有評論*/@ApiOperation(value = "查詢某個歌單下的所有評論")@RequestMapping(value = "/commentOfSongListId",method = RequestMethod.GET)public Object commentOfSongListId(HttpServletRequest request){String songListId = request.getParameter("songListId"); //歌曲idreturn commentService.commentOfSongListId(Integer.parseInt(songListId));}/*** 給某個評論點贊*/@ApiOperation(value = "給某個評論點贊")@RequestMapping(value = "/like",method = RequestMethod.POST)public Object like(HttpServletRequest request){JSONObject jsonObject = new JSONObject();String id = request.getParameter("id").trim(); //主鍵String up = request.getParameter("up").trim(); //用戶id//保存到評論的對象中Comment comment = new Comment();comment.setId(Integer.parseInt(id));comment.setUp(Integer.parseInt(up));boolean flag = commentService.update(comment);if(flag){ //保存成功jsonObject.put(Consts.CODE,1);jsonObject.put(Consts.MSG,"點贊成功");return jsonObject;}jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"點贊失敗");return jsonObject;}}
package com.rabbiter.music.controller;import com.alibaba.fastjson.JSONObject;
import com.rabbiter.music.pojo.Consumer;
import com.rabbiter.music.service.ConsumerService;
import com.rabbiter.music.utils.Consts;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;/*** 前端用戶控制類*/
@RestController
@RequestMapping("/consumer")
@Api(tags = "用戶")
public class ConsumerController {@Autowiredprivate ConsumerService consumerService;/*** 添加前端用戶*/@ApiOperation(value = "注冊、添加前端用戶")@RequestMapping(value = "/add",method = RequestMethod.POST)public Object addConsumer(HttpServletRequest request){JSONObject jsonObject = new JSONObject();String username = request.getParameter("username").trim(); //賬號String password = request.getParameter("password").trim(); //密碼String sex = request.getParameter("sex").trim(); //性別String phoneNum = request.getParameter("phoneNum").trim(); //手機號String email = request.getParameter("email").trim(); //電子郵箱String birth = request.getParameter("birth").trim(); //生日String introduction = request.getParameter("introduction").trim();//簽名String location = request.getParameter("location").trim(); //地區String avator = request.getParameter("avator").trim(); //頭像地址if(username==null||username.equals("")){jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"用戶名不能為空");return jsonObject;}Consumer consumer1 = consumerService.getByUsername(username);if(consumer1!=null){jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"用戶名已存在");return jsonObject;}if(password==null||password.equals("")){jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"密碼不能為空");return jsonObject;}//把生日轉換成Date格式DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");Date birthDate = new Date();try {birthDate = dateFormat.parse(birth);} catch (ParseException e) {e.printStackTrace();}//保存到前端用戶的對象中Consumer consumer = new Consumer();consumer.setUsername(username);consumer.setPassword(password);consumer.setSex(new Byte(sex));consumer.setPhoneNum(phoneNum);consumer.setEmail(email);consumer.setBirth(birthDate);consumer.setIntroduction(introduction);consumer.setLocation(location);consumer.setAvator(avator);boolean flag = consumerService.insert(consumer);if(flag){ //保存成功jsonObject.put(Consts.CODE,1);jsonObject.put(Consts.MSG,"添加成功");return jsonObject;}jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"添加失敗");return jsonObject;}/*** 修改前端用戶*/@ApiOperation(value = "修改前端用戶")@RequestMapping(value = "/update",method = RequestMethod.POST)public Object updateConsumer(HttpServletRequest request){JSONObject jsonObject = new JSONObject();String id = request.getParameter("id").trim(); //主鍵String username = request.getParameter("username").trim(); //賬號String password = request.getParameter("password").trim(); //密碼String sex = request.getParameter("sex").trim(); //性別String phoneNum = request.getParameter("phoneNum").trim(); //手機號String email = request.getParameter("email").trim(); //電子郵箱String birth = request.getParameter("birth").trim(); //生日String introduction = request.getParameter("introduction").trim();//簽名String location = request.getParameter("location").trim(); //地區if(username==null||username.equals("")){jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"用戶名不能為空");return jsonObject;}if(password==null||password.equals("")){jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"密碼不能為空");return jsonObject;}//把生日轉換成Date格式DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");Date birthDate = new Date();try {birthDate = dateFormat.parse(birth);} catch (ParseException e) {e.printStackTrace();}//保存到前端用戶的對象中Consumer consumer = new Consumer();consumer.setId(Integer.parseInt(id));consumer.setUsername(username);consumer.setPassword(password);consumer.setSex(new Byte(sex));consumer.setPhoneNum(phoneNum);consumer.setEmail(email);consumer.setBirth(birthDate);consumer.setIntroduction(introduction);consumer.setLocation(location);boolean flag = consumerService.update(consumer);if(flag){ //保存成功jsonObject.put(Consts.CODE,1);jsonObject.put(Consts.MSG,"修改成功");return jsonObject;}jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"修改失敗");return jsonObject;}/*** 刪除前端用戶*/@ApiOperation(value = "刪除前端用戶")@RequestMapping(value = "/delete",method = RequestMethod.GET)public Object deleteConsumer(HttpServletRequest request){String id = request.getParameter("id").trim(); //主鍵boolean flag = consumerService.delete(Integer.parseInt(id));return flag;}/*** 根據主鍵查詢整個對象*/@ApiOperation(value = "根據主鍵查詢整個對象")@RequestMapping(value = "/selectByPrimaryKey",method = RequestMethod.GET)public Object selectByPrimaryKey(HttpServletRequest request){String id = request.getParameter("id").trim(); //主鍵return consumerService.selectByPrimaryKey(Integer.parseInt(id));}/*** 查詢所有前端用戶*/@ApiOperation(value = "查詢所有前端用戶")@RequestMapping(value = "/allConsumer",method = RequestMethod.GET)public Object allConsumer(HttpServletRequest request){return consumerService.allConsumer();}/*** 更新前端用戶圖片*/@ApiOperation(value = "更新前端用戶圖片")@RequestMapping(value = "/updateConsumerPic",method = RequestMethod.POST)public Object updateConsumerPic(@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")+"userImages";//如果文件路徑不存在,新增該路徑File file1 = new File(filePath);if(!file1.exists()){file1.mkdir();}//實際的文件地址File dest = new File(filePath+System.getProperty("file.separator")+fileName);//存儲到數據庫里的相對文件地址String storeAvatorPath = "/userImages/"+fileName;try {avatorFile.transferTo(dest);Consumer consumer = new Consumer();consumer.setId(id);consumer.setAvator(storeAvatorPath);boolean flag = consumerService.update(consumer);if(flag){jsonObject.put(Consts.CODE,1);jsonObject.put(Consts.MSG,"上傳成功");jsonObject.put("avator",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;}}/*** 前端用戶登錄*/@ApiOperation(value = "前端用戶登錄")@RequestMapping(value = "/login",method = RequestMethod.POST)public Object login(HttpServletRequest request){JSONObject jsonObject = new JSONObject();String username = request.getParameter("username").trim(); //賬號String password = request.getParameter("password").trim(); //密碼if(username==null||username.equals("")){jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"用戶名不能為空");return jsonObject;}if(password==null||password.equals("")){jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"密碼不能為空");return jsonObject;}//保存到前端用戶的對象中Consumer consumer = new Consumer();consumer.setUsername(username);consumer.setPassword(password);boolean flag = consumerService.verifyPassword(username,password);if(flag){ //驗證成功jsonObject.put(Consts.CODE,1);jsonObject.put(Consts.MSG,"登錄成功");jsonObject.put("userMsg",consumerService.getByUsername(username));return jsonObject;}jsonObject.put(Consts.CODE,0);jsonObject.put(Consts.MSG,"用戶名或密碼錯誤");return jsonObject;}
}
五、底部獲取項目(9.9¥帶走)
有問題,或者需要協助調試運行項目的也可以