Java智能音乐推荐网站的优点_计算机毕业设计之JavaWeb个性化音乐推荐系统 音乐网站...

packagecom.controller;importjava.io.IOException;importjava.io.PrintWriter;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.Map;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importnet.sf.json.JSONObject;importcom.entity.SongList;importcom.entity.SongListWithSong;importcom.service.SongListServiceImpl;importcom.service.SongListServiceInter;importcom.service.SongListWithSongServiceImpl;importcom.service.SongListWithSongServiceInter;/*** 标签推荐

*@author29207

**/

public class TagsRecommendServlet extendsHttpServlet {

@Overrideprotected voiddoPost(HttpServletRequest request, HttpServletResponse response)throwsServletException, IOException {

doGet(request, response);

}

@Overrideprotected voiddoGet(HttpServletRequest request, HttpServletResponse response)throwsServletException, IOException {

Map songListTagsNameMap = new HashMap();//存储歌单标签名字和出现次数

java.util.List> songListTagsNameListClassement = new ArrayList>();//存储排序后歌单标签名字和出现次数

PrintWriter out=response.getWriter();//获取歌单编号

String songListIdString = request.getParameter("songListId");int songListId = Integer.parseInt(songListIdString);//歌单编号//声明查询歌单的服务

SongListServiceInter songListService = newSongListServiceImpl();//用于存放所有歌曲存在的所有歌单

ArrayList allSongLists = new ArrayList();//查询该歌单中存在的歌曲//声明songListWithSong(歌曲歌单表服务对象)

SongListWithSongServiceInter songListWithSongService = newSongListWithSongServiceImpl();//调用方法

ArrayList songListWithSongs =songListWithSongService.selectSongListWithSongOfSongLIstId(songListId);//遍历,获取其中的歌曲编号

for(SongListWithSong songListWithSong : songListWithSongs) {int songId = songListWithSong.getSongId();//获取每一个歌曲编号//根据歌曲编号,查询该歌曲存在在哪些歌单中

ArrayList 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= newUserSongListRecommendServlet();

songListTagsNameMap=userSongListRecommendServlet.getSongListTagsNameMap(allSongListsLen, allSongLists, songListTagsNameMap);

songListTagsNameListClassement= userSongListRecommendServlet.songListTagsNameComm(songListTagsNameMap);//标签排序后

int songListTagsNameListClassementLen =songListTagsNameListClassement.size();

JSONObject tagsRecommJsonObject= newJSONObject();

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);

}

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值