use of com.mapper.UserMapper 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;
}
}
use of com.mapper.UserMapper 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;
}
}
use of com.mapper.UserMapper 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);
}
Aggregations