Search in sources :

Example 1 with MovieMapper

use of com.mapper.MovieMapper 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;
    }
}
Also used : RecommendedMovie(com.po.RecommendedMovie) Movie(com.po.Movie) User(com.po.User) ImproveSlopeOne(com.recommender.ImproveSlopeOne) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) RecommendedMovie(com.po.RecommendedMovie) ApplicationContext(org.springframework.context.ApplicationContext) WatchMovieMapper(com.mapper.WatchMovieMapper) RecommendMapper(com.mapper.RecommendMapper) MovieMapper(com.mapper.MovieMapper) WatchMovieMapper(com.mapper.WatchMovieMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with MovieMapper

use of com.mapper.MovieMapper in project Movie by batsqd.

the class MovieController method queryMovies.

@RequestMapping("/queryMovies.action")
public ModelAndView queryMovies() {
    ArrayList<Movie> moviesList = new ArrayList<Movie>();
    ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
    MovieMapper movieMapper = (MovieMapper) ac.getBean("movieMapper");
    Movie movie = movieMapper.selectMovieById(1);
    moviesList.add(movie);
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("moviesList", moviesList);
    modelAndView.setViewName("/WEB-INF/jsp/movie.jsp");
    return modelAndView;
}
Also used : RecommendedMovie(com.po.RecommendedMovie) Movie(com.po.Movie) ApplicationContext(org.springframework.context.ApplicationContext) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) MovieMapper(com.mapper.MovieMapper) WatchMovieMapper(com.mapper.WatchMovieMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with MovieMapper

use of com.mapper.MovieMapper in project Movie by batsqd.

the class MovieInfoService method getMoviesOrderByReleaseTimeToPage.

public ArrayList<Movie> getMoviesOrderByReleaseTimeToPage(String movie_genres, int begain, int end) {
    ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
    MovieMapper movieMapper = (MovieMapper) ac.getBean("movieMapper");
    HashMap<String, Object> parameter = new HashMap<String, Object>();
    ///////--
    parameter.put("movie_genres", "%" + movie_genres + "%");
    parameter.put("begain", begain);
    parameter.put("end", end);
    ArrayList<Movie> moviesList = movieMapper.selectMoviesByReleaseTimeLimit(parameter);
    return moviesList;
}
Also used : Movie(com.po.Movie) ApplicationContext(org.springframework.context.ApplicationContext) HashMap(java.util.HashMap) MovieMapper(com.mapper.MovieMapper)

Example 4 with MovieMapper

use of com.mapper.MovieMapper in project Movie by batsqd.

the class MovieInfoService method getPageCountByKeyWord.

public int getPageCountByKeyWord(int pageSize, String keyWord) {
    ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
    MovieMapper movieMapper = (MovieMapper) ac.getBean("movieMapper");
    int countMovies = movieMapper.selectCountMoviesByKeyWord("%" + keyWord + "%");
    int pageCount = countMovies % 12 == 0 ? countMovies / 12 : (countMovies / 12) + 1;
    return pageCount;
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) MovieMapper(com.mapper.MovieMapper)

Example 5 with MovieMapper

use of com.mapper.MovieMapper in project Movie by batsqd.

the class MovieInfoService method getMoviesBySearchKeyWordToPage.

public ArrayList<Movie> getMoviesBySearchKeyWordToPage(String keyWord, int begain, int end) {
    ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
    MovieMapper movieMapper = (MovieMapper) ac.getBean("movieMapper");
    HashMap<String, Object> parameter = new HashMap<String, Object>();
    parameter.put("keyWord", "%" + keyWord + "%");
    parameter.put("begain", begain);
    parameter.put("end", end);
    ArrayList<Movie> moviesList = movieMapper.selectMoviesBySearchKeyWordLimit(parameter);
    return moviesList;
}
Also used : Movie(com.po.Movie) ApplicationContext(org.springframework.context.ApplicationContext) HashMap(java.util.HashMap) MovieMapper(com.mapper.MovieMapper)

Aggregations

MovieMapper (com.mapper.MovieMapper)14 ApplicationContext (org.springframework.context.ApplicationContext)13 Movie (com.po.Movie)10 HashMap (java.util.HashMap)6 WatchMovieMapper (com.mapper.WatchMovieMapper)5 RecommendedMovie (com.po.RecommendedMovie)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ModelAndView (org.springframework.web.servlet.ModelAndView)5 ArrayList (java.util.ArrayList)4 User (com.po.User)2 RecommendMapper (com.mapper.RecommendMapper)1 UserMapper (com.mapper.UserMapper)1 ImproveSlopeOne (com.recommender.ImproveSlopeOne)1 InputStream (java.io.InputStream)1 Date (java.sql.Date)1 SimpleDateFormat (java.text.SimpleDateFormat)1 SqlSession (org.apache.ibatis.session.SqlSession)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1