@RequestMapping("/login")
public String login(String username,String password,HttpSession session){
User user = userService.login(username,password);
if(user!=null){
//登录成功 将user存储到session
session.setAttribute("user",user);
return "redirect:/index.jsp";
}
return "redirect:/login.jsp";
}
service层代码如下:
//service层
public User login(String username, String password) {
User user = userDao.findByUsernameAndPassword(username,password);
return user;
}
dao层代码如下:
//dao层
public User findByUsernameAndPassword(String username, String password) throws EmptyResultDataAccessException{
User user = jdbcTemplate.queryForObject("select * from sys_user where username=? and password=?", new BeanPropertyRowMapper<User>(User.class), username, password);
return user;
}