欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java 实战范例之精美网上音乐平台的实现

程序员文章站 2022-04-13 08:51:21
一、项目简述本系统功能包括: 音乐播放 用户登录注册 用户信息编辑、头像修改 歌曲、歌单搜索 歌单打分 歌单、歌曲评论 歌单列表、歌手列表分页显示 歌词同步显不 音乐收藏、下载、拖动控制、音粉制 后台...

一、项目简述

本系统功能包括: 音乐播放 用户登录注册 用户信息编辑、头像修改 歌曲、歌单搜索 歌单打分 歌单、歌曲评论 歌单列表、歌手列表分页显示 歌词同步显不 音乐收藏、下载、拖动控制、音粉制 后台对用户、歌曲、歌手、歌单信息的管理

二、项目运行

环境配置: jdk1.8 + tomcat8.5 + mysql + hbuilderx (webstorm也 行)+ eclispe (intellij idea,eclispe,myeclispe,sts都支 持)。

项目技术: springboot + maven + mybatis + vue + redis, b/s 模式+ maven等等

Java 实战范例之精美网上音乐平台的实现

Java 实战范例之精美网上音乐平台的实现

Java 实战范例之精美网上音乐平台的实现

Java 实战范例之精美网上音乐平台的实现

Java 实战范例之精美网上音乐平台的实现

Java 实战范例之精美网上音乐平台的实现

歌手信息操作代码:

@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();
    }
 
//    根据歌手名查找歌手
    @requestmapping(value = "/singer/name/detail", method = requestmethod.get)
    public object singerofname(httpservletrequest req){
        string name = req.getparameter("name").trim();
        return singerservice.singerofname(name);
    }
 
//    根据歌手性别查找歌手
    @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;
        }
    }
}
 

到此这篇关于java 实战范例之精美网上音乐平台的实现的文章就介绍到这了,更多相关java 音乐平台内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!