Search in sources :

Example 1 with Message

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

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

the class StarRating method saveRating.

@RequestMapping("/saveRating.action")
@ResponseBody
public Message saveRating(int userid, int movie_id, int rating) {
    //日志处理
    logger_rating.info(userid + "	" + movie_id + "	" + rating);
    ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
    WatchMovieMapper watchMovieMapper = (WatchMovieMapper) ac.getBean("watchMovieMapper");
    HashMap<String, Object> parameter = new HashMap<String, Object>();
    parameter.put("userid", userid);
    parameter.put("movie_id", movie_id);
    parameter.put("rating", rating);
    //得到long类型当前时间
    long l = System.currentTimeMillis();
    //new日期对象
    Date date = new Date(l);
    //转换提日期输出格式
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    System.out.println(dateFormat.format(date));
    parameter.put("rating_time", date);
    parameter.put("comment", "");
    watchMovieMapper.saveRating(parameter);
    /*
		  ModelAndView modelAndView=new ModelAndView();
		  
		  try{
		     watchMovieMapper.saveRating(parameter);
		     modelAndView.addObject("insertException","感谢您的评分:"+rating+"分!");
		  }catch(Exception e){
			 modelAndView.addObject("insertException","保存数据异常!");
		  }finally{
			  modelAndView.setViewName("/WEB-INF/jsp/movieDetail.jsp");
			  return modelAndView;
		  }*/
    Message message = new Message();
    message.setRegister_prompt_info("1111111111");
    return message;
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Message(com.po.Message) HashMap(java.util.HashMap) WatchMovieMapper(com.mapper.WatchMovieMapper) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.sql.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Message (com.po.Message)2 ApplicationContext (org.springframework.context.ApplicationContext)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 UserMapper (com.mapper.UserMapper)1 WatchMovieMapper (com.mapper.WatchMovieMapper)1 User (com.po.User)1 Date (java.sql.Date)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1