登錄模塊
阿新 • • 發佈:2017-09-16
地址 redirect system map ping ima gin () null
Git 地址:https://github.com/705645051/vip
1. 添加login.jsp和index.jsp等文件
(代碼略)
2. 添加視圖文件
@Controller public class PageController { @RequestMapping("/page/login.do") public String getLogin(){ return "login" ; } @RequestMapping("/page/index.do") public String getIndex(){ return"index" ; } } @Controller public class UserController { @Autowired UserService userService ; @RequestMapping("/login.do") public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model model){ System.out.println("UserController login username : " + username); System.out.println("UserController login password : " + password); if(!userService.login(username,password)){ model.addAttribute("error","用戶名不存在或密碼錯誤") ; return "redirect:/page/login.do" ; } return "redirect:/page/index.do" ; } }
3. 添加業務層代碼
@Service public class UserService { @Autowired UserMapper userMapper ;public boolean login(String username,String password){ UserExample userExample = new UserExample() ; userExample .createCriteria() .andAccountEqualTo(username) .andPasswordEqualTo(password) ; List<User> userList = userMapper.selectByExample(userExample) ; return userList != null && userList.size() > 0 ; } }
4. 登錄界面演示
登錄模塊