Java 實戰(zhàn)范例之精美網(wǎng)上音樂平臺的實現(xiàn)
一、項目簡述
本系統(tǒng)功能包括: 音樂播放 用戶登錄注冊 用戶信息編輯、頭像修改 歌曲、歌單搜索 歌單打分 歌單、歌曲評論 歌單列表、歌手列表分頁顯示 歌詞同步顯不 音樂收藏、下載、拖動控制、音粉制 后臺對用戶、歌曲、歌手、歌單信息的管理
二、項目運行
環(huán)境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX (Webstorm也 行)+ Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts都支 持)。
項目技術(shù): Springboot + Maven + Mybatis + Vue + Redis, B/S 模式+ Maven等等






歌手信息操作代碼:
@RestController
@Controller
public class SingerController {
@Autowired
private SingerServiceImpl singerService;
@Configuration
public class MyPicConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// registry.addResourceHandler("/img/singerPic/**").addResourceLocations("file:/Users/hongweiyin/Documents/github-workspace/music-website/music-server/img/singerPic/");
}
}
// 添加歌手
@ResponseBody
@RequestMapping(value = "/singer/add", method = RequestMethod.POST)
public Object addSinger(HttpServletRequest req){
JSONObject jsonObject = new JSONObject();
String name = req.getParameter("name").trim();
String sex = req.getParameter("sex").trim();
String pic = req.getParameter("pic").trim();
String birth = req.getParameter("birth").trim();
String location = req.getParameter("location").trim();
String introduction = req.getParameter("introduction").trim();
Singer singer = new Singer();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date myBirth = new Date();
try {
myBirth = dateFormat.parse(birth);
}catch (Exception e){
e.printStackTrace();
}
singer.setName(name);
singer.setSex(new Byte(sex));
singer.setPic(pic);
singer.setBirth(myBirth);
singer.setLocation(location);
singer.setIntroduction(introduction);
boolean res = singerService.addSinger(singer);
if (res){
jsonObject.put("code", 1);
jsonObject.put("msg", "添加成功");
return jsonObject;
}else {
jsonObject.put("code", 0);
jsonObject.put("msg", "添加失敗");
return jsonObject;
}
}
// 返回所有歌手
@RequestMapping(value = "/singer", method = RequestMethod.GET)
public Object allSinger(){
return singerService.allSinger();
}
// 根據(jù)歌手名查找歌手
@RequestMapping(value = "/singer/name/detail", method = RequestMethod.GET)
public Object singerOfName(HttpServletRequest req){
String name = req.getParameter("name").trim();
return singerService.singerOfName(name);
}
// 根據(jù)歌手性別查找歌手
@RequestMapping(value = "/singer/sex/detail", method = RequestMethod.GET)
public Object singerOfSex(HttpServletRequest req){
String sex = req.getParameter("sex").trim();
return singerService.singerOfSex(Integer.parseInt(sex));
}
// 刪除歌手
@RequestMapping(value = "/singer/delete", method = RequestMethod.GET)
public Object deleteSinger(HttpServletRequest req){
String id = req.getParameter("id");
return singerService.deleteSinger(Integer.parseInt(id));
}
// 更新歌手信息
@ResponseBody
@RequestMapping(value = "/singer/update", method = RequestMethod.POST)
public Object updateSingerMsg(HttpServletRequest req){
JSONObject jsonObject = new JSONObject();
String id = req.getParameter("id").trim();
String name = req.getParameter("name").trim();
String sex = req.getParameter("sex").trim();
String pic = req.getParameter("pic").trim();
String birth = req.getParameter("birth").trim();
String location = req.getParameter("location").trim();
String introduction = req.getParameter("introduction").trim();
Singer singer = new Singer();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date myBirth = new Date();
try {
myBirth = dateFormat.parse(birth);
}catch (Exception e){
e.printStackTrace();
}
singer.setId(Integer.parseInt(id));
singer.setName(name);
singer.setSex(new Byte(sex));
singer.setPic(pic);
singer.setBirth(myBirth);
singer.setLocation(location);
singer.setIntroduction(introduction);
boolean res = singerService.updateSingerMsg(singer);
if (res){
jsonObject.put("code", 1);
jsonObject.put("msg", "修改成功");
return jsonObject;
}else {
jsonObject.put("code", 0);
jsonObject.put("msg", "修改失敗");
return jsonObject;
}
}
// 更新歌手頭像
@ResponseBody
@RequestMapping(value = "/singer/avatar/update", method = RequestMethod.POST)
public Object updateSingerPic(@RequestParam("file") MultipartFile avatorFile, @RequestParam("id")int id){
JSONObject jsonObject = new JSONObject();
if (avatorFile.isEmpty()) {
jsonObject.put("code", 0);
jsonObject.put("msg", "文件上傳失?。?);
return jsonObject;
}
String fileName = System.currentTimeMillis()+avatorFile.getOriginalFilename();
String filePath = System.getProperty("user.dir") + System.getProperty("file.separator") + "img" + System.getProperty("file.separator") + "singerPic" ;
File file1 = new File(filePath);
if (!file1.exists()){
file1.mkdir();
}
File dest = new File(filePath + System.getProperty("file.separator") + fileName);
String storeAvatorPath = "/img/singerPic/"+fileName;
try {
avatorFile.transferTo(dest);
Singer singer = new Singer();
singer.setId(id);
singer.setPic(storeAvatorPath);
boolean res = singerService.updateSingerPic(singer);
if (res){
jsonObject.put("code", 1);
jsonObject.put("pic", storeAvatorPath);
jsonObject.put("msg", "上傳成功");
return jsonObject;
}else {
jsonObject.put("code", 0);
jsonObject.put("msg", "上傳失敗");
return jsonObject;
}
}catch (IOException e){
jsonObject.put("code", 0);
jsonObject.put("msg", "上傳失敗" + e.getMessage());
return jsonObject;
}finally {
return jsonObject;
}
}
}
到此這篇關(guān)于Java 實戰(zhàn)范例之精美網(wǎng)上音樂平臺的實現(xiàn)的文章就介紹到這了,更多相關(guān)Java 音樂平臺內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot實現(xiàn)異步任務(wù)的項目實踐
本文將使用SpringBoot 去實現(xiàn)異步之間的調(diào)用,提高系統(tǒng)的并發(fā)性能、用戶體驗,具有一定的參考價值,感興趣的可以了解一下2023-10-10
Easypoi 輕松實現(xiàn)復(fù)雜excel文件導(dǎo)出功能
這篇文章主要介紹了Easypoi 輕松實現(xiàn)復(fù)雜excel文件導(dǎo)出功能,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-11-11
淺析SpringBoot統(tǒng)一返回結(jié)果的實現(xiàn)
前后端開發(fā)過程中數(shù)據(jù)交互規(guī)范化是一件非常重要的事情,不僅可以減少前后端交互過程中出現(xiàn)的問題,也讓代碼邏輯更加具有條理,下面小編就和大家講講SpringBoot如何統(tǒng)一返回結(jié)果的吧2023-07-07
springBoot+dubbo+zookeeper實現(xiàn)分布式開發(fā)應(yīng)用的項目實踐
本文主要介紹了springBoot+dubbo+zookeeper實現(xiàn)分布式開發(fā)應(yīng)用的項目實踐,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-03-03
Java synchronized關(guān)鍵字和Lock接口實現(xiàn)原理
這篇文章主要介紹了Java synchronized關(guān)鍵字和Lock接口實現(xiàn)原理,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-12-12

