Search in sources :

Example 1 with User

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

the class LoginController method register.

@RequestMapping("/register.action")
@ResponseBody
public Message register(String username, String password) {
    ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
    UserMapper userMapper = (UserMapper) ac.getBean("userMapper");
    User user = userMapper.selectUserByUsername(username);
    Message message = new Message();
    if (user == null) {
        //不存在该用户,可以注册
        User register_user = new User();
        register_user.setUsername(username);
        register_user.setUserpasswd(password);
        try {
            userMapper.insertUsetByUsername(register_user);
        } catch (Exception e) {
            //插入数据库异常,跳转至失败页面
            message.setRegister_prompt_info("抱歉,注册信息保存失败,请再次尝试!");
            return message;
        }
        //数据保存成功
        message.setRegister_prompt_info("嘻嘻,注册成功!");
        return message;
    } else {
        //该用户名被占用,调到失败
        message.setRegister_prompt_info("用户名被占用,请更换!");
        return message;
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) UserMapper(com.mapper.UserMapper) User(com.po.User) Message(com.po.Message) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with User

use of com.po.User 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 3 with User

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

the class LoginController method validation.

@RequestMapping("/validation.action")
@ResponseBody
public User validation(String username, String password, HttpSession session) {
    //如果用户名不是yzy,itemsShow.jsp退出会失败
    ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
    UserMapper userMapper = (UserMapper) ac.getBean("userMapper");
    User user = userMapper.selectUserByUsername(username);
    if (user != null && user.getUserpasswd().equals(password)) {
        //登录成功,设置session
        session.setAttribute("user", user);
        return user;
    } else {
        //登录失败,返回登录页面
        return null;
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) UserMapper(com.mapper.UserMapper) User(com.po.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with User

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

the class SpringMybatis method main.

public static void main(String[] args) {
    // TODO Auto-generated method stub
    ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
    MovieMapper movieMapper = (MovieMapper) ac.getBean("movieMapper");
    System.out.println(movieMapper.selectMovieById(2));
    UserMapper userMapper = (UserMapper) ac.getBean("userMapper");
    User user = userMapper.selectUserByUsername("yzy");
    System.out.print(user);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) UserMapper(com.mapper.UserMapper) User(com.po.User) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MovieMapper(com.mapper.MovieMapper)

Aggregations

User (com.po.User)4 ApplicationContext (org.springframework.context.ApplicationContext)4 UserMapper (com.mapper.UserMapper)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 MovieMapper (com.mapper.MovieMapper)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 RecommendMapper (com.mapper.RecommendMapper)1 WatchMovieMapper (com.mapper.WatchMovieMapper)1 Message (com.po.Message)1 Movie (com.po.Movie)1 RecommendedMovie (com.po.RecommendedMovie)1 ImproveSlopeOne (com.recommender.ImproveSlopeOne)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1