use of com.mapper.RecommendMapper in project Movie by batsqd.
the class StarRating method saveUserFeedbackRating.
/////////////////////////////////////////
@RequestMapping("/saveUserFeedbackRating.action")
public ModelAndView saveUserFeedbackRating(int user_id, int movie_id, int user_feedback_rating) {
//日志处理
logger_rating.info(user_id + " " + movie_id + " " + user_feedback_rating);
//在这里只是update feedback
ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
RecommendMapper recommendMapper = (RecommendMapper) ac.getBean("recommendMapper");
HashMap<String, Object> parameter = new HashMap<String, Object>();
parameter.put("movie_id", movie_id);
parameter.put("user_id", user_id);
parameter.put("user_feedback_rating", user_feedback_rating);
ModelAndView modelAndView = new ModelAndView();
try {
recommendMapper.saveUserFeedbackRating(parameter);
modelAndView.addObject("insertException", "感谢您的评分:" + user_feedback_rating + "分!");
} catch (Exception e) {
modelAndView.addObject("insertException", "保存数据异常!");
} finally {
modelAndView.setViewName("/WEB-INF/jsp/userFeedback.jsp");
return modelAndView;
}
}
use of com.mapper.RecommendMapper in project Movie by batsqd.
the class MovieController method getRecommendedMoviesByOurAlgorithm.
/////////////////////////////////////////////////////
@RequestMapping("getRecommendedMoviesByOurAlgorithm.action")
public ModelAndView getRecommendedMoviesByOurAlgorithm(HttpSession session) throws Exception {
User user = (User) session.getAttribute("user");
int user_id = user.getUserid();
int recommend_movie_num = Configs.recommend_movie_num;
ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
WatchMovieMapper watchMovieMapper = (WatchMovieMapper) ac.getBean("watchMovieMapper");
int numsOfRatedMoviesByUserId = watchMovieMapper.numsOfRatedMoviesByUserId(user_id);
ModelAndView modelAndView = new ModelAndView();
if (numsOfRatedMoviesByUserId < 5) {
modelAndView.addObject("numsOfRatedMoviesByUserId", numsOfRatedMoviesByUserId);
modelAndView.setViewName("/WEB-INF/jsp/guessYouLike.jsp");
return modelAndView;
} else {
//超过5人评价,才做预测
ImproveSlopeOne improveSlopeOne = new ImproveSlopeOne();
List<RecommendedMovie> recommendedMovieslist = improveSlopeOne.getPredictMovies(user_id, recommend_movie_num);
//System.out.println("=========================================");
//System.out.println("推荐电影的数量:"+recommendedMovieslist.size());
//System.out.println(recommendedMovieslist.toString());
//System.out.println("==========================================");
MovieMapper movieMapper = (MovieMapper) ac.getBean("movieMapper");
RecommendMapper recommendMapper = (RecommendMapper) ac.getBean("recommendMapper");
ArrayList<Movie> moviesList = new ArrayList<Movie>();
for (int i = 0; i < recommendedMovieslist.size(); i++) {
double movie_recommend_value = recommendedMovieslist.get(i).getRecommend_vale();
int recommendedMovie_id = recommendedMovieslist.get(i).getMovie_id();
HashMap<String, Object> parameter = new HashMap<String, Object>();
parameter.put("movie_id", recommendedMovie_id);
parameter.put("user_id", user_id);
parameter.put("recommend_value", movie_recommend_value);
//最好处理下异常
//只是保存user_id movie_id recommend_value timestamp
recommendMapper.saveRecommendedMovies(parameter);
Movie movie = movieMapper.selectMovieById(recommendedMovie_id);
if (movie != null) {
moviesList.add(movie);
}
}
modelAndView.addObject("moviesList", moviesList);
modelAndView.setViewName("/WEB-INF/jsp/guessYouLike.jsp");
return modelAndView;
}
}
Aggregations