并非是那种传授并分享知识的,只想在个人博客上把自己学的东西记录下来,也希望我记录的东西对各位看官有帮助。
先附上结构目录跟效果图
在上一篇的项目中只增加了controller方法和增加login.html页面
login页面
< span style = "font-size:18px;" > < strong > < body > < form action = "/front/addlogin" name = "loginfrom" accept-charset = "utf-8" method = "post" > < label class = "label-tips" for = "u" > 账号: </ label > < input type = "text" id = "u" name = "username" class = "inputstyle" /> < div > < label class = "lable-tips" for = "password" > 密码: </ label > < input type = "password" id = "password" name = "password" class = "inputstyle" /> </ div > < input type = "submit" name = "登录" /> < a href = "register.html" class = "zcxy" target = "_blank" > 注册 </ a > </ form > </ body > </ strong > </ span >
controller
< span style = "font-size:18px;" > < strong > @Controller @RequestMapping("/front/*") public class IndexController { @Autowired private UserDao userDao; //index页面 @RequestMapping("/index") public String index() { return "index"; } //注册页面 @RequestMapping("/register") public String register(){ return "register"; } //登录页面 @RequestMapping("/login") public String login(){ return "login"; } //注册方法 @RequestMapping("/addregister") public String register(HttpServletRequest request){ String username = request .getParameter("username"); String password = request .getParameter("password"); String password2 = request .getParameter("password2"); if (password.equals(password2)){ UserEntity userEntity = new UserEntity(); userEntity.setUsername(username); userEntity.setPassword(password); userDao.save(userEntity); return "login"; }else { return "register"; } } //登录方法 @RequestMapping("/addlogin") public String login(HttpServletRequest request){ String username = request .getParameter("username"); String password = request .getParameter("password"); UserEntity userEntity = userDao .findByUsernameAndPassword(username,password); String str = "" ; if (userEntity !=null){ str = "index" ; }else { str = "login" ; } return str; } }</ strong > </ span >
SpringBoot最简易版本的登录注册完成