文章目录
- 音乐系统
- 一、项目演示
- 二、项目介绍
- 三、万字项目文档
- 四、部分功能截图
- 五、部分代码展示
- 六、底部获取项目源码和万字论文参考(9.9¥带走)
音乐系统
一、项目演示
在线音乐系统
二、项目介绍
基于springboot+vue的前后端分离在线音乐系统
登录角色 : 用户、管理员
用户:歌单分类分页界面,歌手分类分页界面,我的音乐查看收藏歌曲,搜索音乐,可根据歌手、歌曲、歌单名进行搜索;头像修改、用户信息修改,歌曲播放,进度条拉伸,歌词加载,歌曲收藏,歌曲下载,登录、注册等
管理员:系统首页展示统计数据,用户管理,歌手管理,歌曲管理(修改音源,歌词,后台评论),上传音乐
项目技术
语言:java
前端技术:Vue、 ELementUI、echarts
后端技术:SpringBoot、Mybatis-Plus
数据库: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 {
@Autowired
private CollectService CollectService;
/**
* 添加收藏
*/
@ApiOperation(value = "添加收藏、取消收藏")
@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))){
CollectService.deleteByUserIdSongId(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"); //用户id
String songId = request.getParameter("songId"); //歌曲id
boolean 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"); //用户id
return CollectService.collectOfUserId(Integer.parseInt(userId));
}
}
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 com.rabbiter.music.utils.PathUtils;
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 {
@Autowired
private 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 = PathUtils.getClassLoadRootPath() +"/userImages/";
//如果文件路径不存在,新增该路径
File file1 = new File(filePath);
if(!file1.exists()){
file1.mkdir();
}
//实际的文件地址
File dest = new File(filePath + 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;
}
}
package com.rabbiter.music.controller;
import com.alibaba.fastjson.JSONObject;
import com.rabbiter.music.pojo.Song;
import com.rabbiter.music.service.SongService;
import com.rabbiter.music.utils.Consts;
import com.rabbiter.music.utils.PathUtils;
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;
/**
* 歌曲管理controller
*/
@RestController
@RequestMapping("/song")
@Api(tags = "歌曲管理")
public class SongController {
@Autowired
private SongService songService;
/**
* 添加歌曲
*/
@ApiOperation(value = "添加歌曲")
@RequestMapping(value = "/add",method = RequestMethod.POST)
public Object addSong(HttpServletRequest request, @RequestParam("file")MultipartFile mpFile){
JSONObject jsonObject = new JSONObject();
//获取前端传来的参数
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;
}
//文件名=当前时间到毫秒+原来的文件名
String fileName = System.currentTimeMillis()+mpFile.getOriginalFilename();
//文件路径
String filePath = PathUtils.getClassLoadRootPath() + "/song/";
//如果文件路径不存在,新增该路径
File file1 = new File(filePath);
if(!file1.exists()){
file1.mkdir();
}
//实际的文件地址
File dest = new File(filePath + fileName);
//存储到数据库里的相对文件地址
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);
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;
}
}
/**
* 根据歌手id查询歌曲
*/
@ApiOperation(value = "根据歌手id查询歌曲")
@RequestMapping(value = "/singer/detail",method = RequestMethod.GET)
public Object songOfSingerId(HttpServletRequest request){
String singerId = request.getParameter("singerId");
return songService.songOfSingerId(Integer.parseInt(singerId));
}
/**
* 修改歌曲
*/
@ApiOperation(value = "修改歌曲")
@RequestMapping(value = "/update",method = RequestMethod.POST)
public Object updateSong(HttpServletRequest request){
JSONObject jsonObject = new JSONObject();
String id = request.getParameter("id").trim(); //主键
String name = request.getParameter("name").trim(); //歌名
String introduction = request.getParameter("introduction").trim();//专辑
String lyric = request.getParameter("lyric").trim(); //歌词
//保存到歌手的对象中
Song song = new Song();
song.setId(Integer.parseInt(id));
song.setName(name);
song.setIntroduction(introduction);
song.setLyric(lyric);
boolean flag = songService.update(song);
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 deleteSinger(HttpServletRequest request){
//-TODO 先查询到数据库中对应的文件地址,删除掉它再进行下面的代码
String id = request.getParameter("id").trim(); //主键
boolean flag = songService.delete(Integer.parseInt(id));
return flag;
}
/**
* 更新歌曲图片
*/
@ApiOperation(value = "更新歌曲图片")
@RequestMapping(value = "/updateSongPic",method = RequestMethod.POST)
public Object updateSongPic(@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 = PathUtils.getClassLoadRootPath() + "/img/songPic/";
//如果文件路径不存在,新增该路径
File file1 = new File(filePath);
if(!file1.exists()){
file1.mkdir();
}
//实际的文件地址
File dest = new File(filePath + fileName);
//存储到数据库里的相对文件地址
String storeAvatorPath = "/img/songPic/"+fileName;
try {
avatorFile.transferTo(dest);
Song song = new Song();
song.setId(id);
song.setPic(storeAvatorPath);
boolean flag = songService.update(song);
if(flag){
jsonObject.put(Consts.CODE,1);
jsonObject.put(Consts.MSG,"上传成功");
jsonObject.put("pic",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 = "/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 = PathUtils.getClassLoadRootPath() + "/song/";
//如果文件路径不存在,新增该路径
File file1 = new File(filePath);
if(!file1.exists()){
file1.mkdir();
}
//实际的文件地址
File dest = new File(filePath + fileName);
//存储到数据库里的相对文件地址
String storeAvatorPath = "/song/"+fileName;
try {
avatorFile.transferTo(dest);
Song song = new Song();
song.setId(id);
song.setUrl(storeAvatorPath);
boolean flag = songService.update(song);
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;
}
}
/**
* 根据歌曲id查询歌曲对象
*/
@ApiOperation(value = "根据歌曲id查询歌曲对象")
@RequestMapping(value = "/detail",method = RequestMethod.GET)
public Object detail(HttpServletRequest request){
String songId = request.getParameter("songId");
return songService.selectByPrimaryKey(Integer.parseInt(songId));
}
/**
* 根据歌手名字精确查询歌曲
*/
@ApiOperation(value = "根据歌手名字精确查询歌曲")
@RequestMapping(value = "/songOfSongName",method = RequestMethod.GET)
public Object songOfSongName(HttpServletRequest request){
String songName = request.getParameter("songName");
return songService.songOfName(songName);
}
/**
* 根据歌手名字模糊查询歌曲
*/
@ApiOperation(value = "根据歌手名字模糊查询歌曲")
@RequestMapping(value = "/likeSongOfName",method = RequestMethod.GET)
public Object likeSongOfName(HttpServletRequest request){
String songName = request.getParameter("songName");
return songService.likeSongOfName(songName);
}
/**
* 查询所有歌曲
*/
@ApiOperation(value = "查询所有歌曲")
@RequestMapping(value = "/allSong",method = RequestMethod.GET)
public Object allSong(HttpServletRequest request){
return songService.allSong();
}
}
六、底部获取项目源码和万字论文参考(9.9¥带走)
有问题,或者需要协助调试运行项目的也可以