Search in sources :

Example 1 with Movie

use of com.po.Movie 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 Movie

use of com.po.Movie 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 Movie

use of com.po.Movie in project Movie by batsqd.

the class SearchMovieController method showSearchContent.

@RequestMapping("/showSearchContent.action")
public ModelAndView showSearchContent(String keyWord) throws UnsupportedEncodingException {
    //防止中文乱码
    String decode_keyWord = URLDecoder.decode(keyWord, "UTF-8");
    System.out.println("decode_keyWord" + decode_keyWord);
    System.out.println("keyWord" + keyWord);
    ModelAndView modelAndView = new ModelAndView();
    MovieInfoService movieInfoService = new MovieInfoService();
    ArrayList<Movie> moviesList = new ArrayList<Movie>();
    int pageCount = 0;
    if (decode_keyWord != null) {
        //search box提交的请求
        moviesList = movieInfoService.getMoviesBySearchKeyWordToPage(decode_keyWord, 0, 12);
        pageCount = movieInfoService.getPageCountByKeyWord(12, decode_keyWord);
    }
    if (pageCount > 1) {
        //此时有下一页
        modelAndView.addObject("navigation", "<a href='http://yuanzhiyuan-pc:8080/Movie/getSearchMovieByPage.action?pageNow=1&keyWord=" + URLEncoder.encode(URLEncoder.encode(decode_keyWord, "UTF-8"), "UTF-8") + "'>下一页</a>" + "&nbsp;&nbsp;共" + pageCount + "页!");
    }
    modelAndView.addObject("moviesList", moviesList);
    modelAndView.setViewName("/WEB-INF/jsp/ShowSearchResult.jsp");
    return modelAndView;
}
Also used : Movie(com.po.Movie) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) MovieInfoService(com.service.MovieInfoService) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Movie

use of com.po.Movie in project Movie by batsqd.

the class SearchMovieController method getSearchMovieByPage.

@RequestMapping("/getSearchMovieByPage.action")
public ModelAndView getSearchMovieByPage(int pageNow, String keyWord) throws UnsupportedEncodingException {
    int pageSize = 12;
    int pageCount = 1;
    int begain = 0;
    int end = 5;
    begain = (pageNow) * pageSize;
    end = begain + pageSize;
    //防止中文乱码
    String decode_keyWord = URLDecoder.decode(keyWord, "UTF-8");
    MovieInfoService movieInfoService = new MovieInfoService();
    ArrayList<Movie> moviesList = movieInfoService.getMoviesBySearchKeyWordToPage(decode_keyWord, begain, end);
    pageCount = movieInfoService.getPageCountByKeyWord(pageSize, decode_keyWord);
    ModelAndView modelAndView = new ModelAndView();
    String navigationUrlPre = "";
    String navigationUrlNext = "";
    if (pageNow < 1) {
        //没有上一页;
        navigationUrlPre = "";
    } else {
        //有上一页
        navigationUrlPre = "<a href='http://yuanzhiyuan-pc:8080/Movie/getSearchMovieByPage.action?pageNow=" + (pageNow - 1) + "&keyWord=" + URLEncoder.encode(URLEncoder.encode(decode_keyWord, "UTF-8"), "UTF-8") + "'>上一页</a>";
    }
    if (pageNow + 1 < pageCount) {
        //有下一页
        navigationUrlNext = "<a href='http://yuanzhiyuan-pc:8080/Movie/getSearchMovieByPage.action?pageNow=" + (pageNow + 1) + "&keyWord=" + URLEncoder.encode(URLEncoder.encode(decode_keyWord, "UTF-8"), "UTF-8") + "'>下一页</a>";
    } else {
        //没有下一页
        navigationUrlNext = "";
    }
    modelAndView.addObject("moviesList", moviesList);
    modelAndView.addObject("navigation", "当前为第" + (pageNow + 1) + "页&nbsp;&nbsp;" + navigationUrlPre + "  " + navigationUrlNext + " " + "&nbsp;&nbsp;共" + pageCount + "页!");
    modelAndView.setViewName("/WEB-INF/jsp/ShowSearchResult.jsp");
    return modelAndView;
}
Also used : Movie(com.po.Movie) ModelAndView(org.springframework.web.servlet.ModelAndView) MovieInfoService(com.service.MovieInfoService) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Movie

use of com.po.Movie in project Movie by batsqd.

the class FrameController method showRomance.

@RequestMapping("/romance.action")
public ModelAndView showRomance(String type, String genres) {
    //type指的是按照流派,按照发行时间,按照评分
    ModelAndView modelAndView = new ModelAndView();
    MovieInfoService movieInfoService = new MovieInfoService();
    ArrayList<Movie> moviesList = new ArrayList<Movie>();
    int pageCount = 0;
    if ("byGenres".equals(type)) {
        moviesList = movieInfoService.getMoviesByGenresToPage(genres, 0, 12);
        pageCount = movieInfoService.getPageCountByGenres(12, genres);
    } else if ("byReleaseTime".equals(type)) {
        //此处按发布时间指的是按照Romance类别中电影的发布时间顺序
        moviesList = movieInfoService.getMoviesOrderByReleaseTimeToPage(genres, 0, 12);
        pageCount = movieInfoService.getPageCountByGenres(12, genres);
    } else if ("byRating".equals(type)) {
        moviesList = movieInfoService.getMoviesOrderByRatingToPage(genres, 0, 12);
        pageCount = movieInfoService.getPageCountByGenres(12, genres);
    }
    if (pageCount > 1) {
        //此时有下一页
        modelAndView.addObject("navigation", "<a href='http://yuanzhiyuan-pc:8080/Movie/getMoviesByPage.action?pageNow=1&type=" + type + "&genres=" + genres + "'>下一页</a>" + "&nbsp;&nbsp;共" + pageCount + "页!");
    }
    modelAndView.addObject("genres", genres);
    modelAndView.addObject("moviesList", moviesList);
    //genres=romance,所有的类型都可以调到同一个页面
    modelAndView.setViewName("/WEB-INF/jsp/romance.jsp");
    return modelAndView;
}
Also used : Movie(com.po.Movie) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) MovieInfoService(com.service.MovieInfoService) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Movie (com.po.Movie)15 MovieMapper (com.mapper.MovieMapper)10 ApplicationContext (org.springframework.context.ApplicationContext)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ModelAndView (org.springframework.web.servlet.ModelAndView)9 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 WatchMovieMapper (com.mapper.WatchMovieMapper)5 RecommendedMovie (com.po.RecommendedMovie)5 MovieInfoService (com.service.MovieInfoService)4 RecommendMapper (com.mapper.RecommendMapper)1 User (com.po.User)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