計算機畢業設計之JavaWeb個性化音樂推薦系統 音樂網站

開發技術

前端:JQuery HTML CSS

后端:JSP+Servlet+JDBC

算法:標簽推薦、熱門推薦

代碼開源地址

https://gitee.com/bysj2021/music

特色

推薦算法、注釋豐富、純經典MVC架構

功能

1、用戶登錄

(1) 用戶基本信息展示、修改

(2) 用戶收藏列表

(3) 用戶聽歌記錄

2、網站主要實現功能

(1) 熱門歌曲推薦

(2) 用戶喜歡歌曲推薦

(3) 歌曲排行推薦

① 人氣排行(根據聽曲人數總量確定)

② 下載排行(根據歌曲下載次數確定)

③ 收藏排行(根據歌曲被收藏的次數確定)

(4) 歌曲搜索

(5) 歌曲評論及展示

(6) 歌曲區分類展示(為歌曲定義標簽并分標簽展示)

(7) 用戶給歌曲打標簽(標簽是系統推薦的標簽,用戶只能在其中選擇(此標簽在整個系統中不起作用,只對于此用戶起作用))

3、管理員功能

(1) 管理員頁面與普通用戶頁面展示不同

(2) 上傳并管理所有歌曲

① 上傳歌曲

② 為歌曲定義標簽

③ 刪除歌曲

④ 修改歌曲基本信息

(3) 管理用戶信息

(4) 管理評論信息

運行截圖

個性化音樂推薦系統
個性化音樂推薦系統
個性化音樂推薦系統
個性化音樂推薦系統
個性化音樂推薦系統
個性化音樂推薦系統
個性化音樂推薦系統
個性化音樂推薦系統
個性化音樂推薦系統
個性化音樂推薦系統

核心推薦算法代碼實現

package com.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import com.entity.SongList;
import com.entity.SongListWithSong;
import com.service.SongListServiceImpl;
import com.service.SongListServiceInter;
import com.service.SongListWithSongServiceImpl;
import com.service.SongListWithSongServiceInter;

/**
 * 標簽推薦
 * @author 29207
 *
 */
public class TagsRecommendServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Map<String, Integer> songListTagsNameMap = new HashMap<String, Integer>();//存儲歌單標簽名字和出現次數
        java.util.List<Map.Entry<String, Integer>> songListTagsNameListClassement = new ArrayList<Map.Entry<String,Integer>>();//存儲排序后歌單標簽名字和出現次數
        
        PrintWriter out = response.getWriter();
        //獲取歌單編號
        String songListIdString = request.getParameter("songListId");
        int songListId = Integer.parseInt(songListIdString);//歌單編號
        
        //聲明查詢歌單的服務
        SongListServiceInter songListService = new SongListServiceImpl();
        
        //用于存放所有歌曲存在的所有歌單
        ArrayList<SongList> allSongLists = new ArrayList<SongList>();
        
        //查詢該歌單中存在的歌曲
        //聲明songListWithSong(歌曲歌單表服務對象)
        SongListWithSongServiceInter songListWithSongService = new SongListWithSongServiceImpl();
        //調用方法
        ArrayList<SongListWithSong> songListWithSongs = songListWithSongService.selectSongListWithSongOfSongLIstId(songListId);
        //遍歷,獲取其中的歌曲編號
        for (SongListWithSong songListWithSong : songListWithSongs) {
            int songId = songListWithSong.getSongId();//獲取每一個歌曲編號
            //根據歌曲編號,查詢該歌曲存在在哪些歌單中
            ArrayList<SongListWithSong> songFromSongLists = songListWithSongService.selectSongListIdFromSongListWithSongOfSongId(songId);
            //遍歷,取出每個歌單的歌單編號,根據歌單編號查找歌單
            for (SongListWithSong songListWithSong2 : songFromSongLists) {
                int oneSongFromsongListId = songListWithSong2.getSongListId();
                //根據歌單編號查詢歌單信息
                SongList oneSongList = songListService.selectSongListOfSongListId(oneSongFromsongListId);
                //把該歌單存入allSongLists
                allSongLists.add(oneSongList);
            }
        }
        System.out.println("==========我是標簽推薦服務=========");
        //一個歌單中所有歌曲涉及到的所有歌單為allSongLists
        int allSongListsLen = allSongLists.size();
        UserSongListRecommendServlet userSongListRecommendServlet = new UserSongListRecommendServlet();
        songListTagsNameMap = userSongListRecommendServlet.getSongListTagsNameMap(allSongListsLen, allSongLists, songListTagsNameMap);
        songListTagsNameListClassement = userSongListRecommendServlet.songListTagsNameComm(songListTagsNameMap);//標簽排序后
        int songListTagsNameListClassementLen =  songListTagsNameListClassement.size();
        JSONObject tagsRecommJsonObject = new JSONObject();
        System.out.println("排序后長度:" + songListTagsNameListClassementLen);
        if (songListTagsNameListClassementLen == 0) {
            out.print("null");
        }else {
            if (songListTagsNameListClassementLen <= 5) {
                for (int i = 0; i < songListTagsNameListClassementLen; i++) {
                    String tagsRecomm = songListTagsNameListClassement.get(i).getKey();
                    tagsRecommJsonObject.put(i, tagsRecomm);
                }
            }else {
                for (int i = 0; i < 5; i++) {
                    String tagsRecomm = songListTagsNameListClassement.get(i).getKey();
                    tagsRecommJsonObject.put(i, tagsRecomm);
                }
            }
            System.out.println("推薦標簽JSON===" + tagsRecommJsonObject);
            out.print(tagsRecommJsonObject);
        }
    }
}

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容