Spring boot+idea+MySQL实现简单的用户登录功能

环境:idea+spring boot 2.1.0  + 数据库MySQL

需求:在前端页面输入用户名和密码进入数据库里验证,若和数据库里匹配则跳转到新的页面,若不匹配则返回登录页面

ps:笔者也是新手,最近在学习spring boot框架,希望通过这样的方式来巩固和提升自己,有不足之处欢迎指出,加油!么么

第一步:搭建好spring boot,保证能运行,MySQL新建一张user表,字段自己定,有主键,用户名,密码就够了,例如Spring boot+idea+MySQL实现简单的用户登录功能_第1张图片

第二步:pom.xml依赖加入thymeleaf模板,与jsp类似,spring boot官方默认使用thymeleaf

Spring boot+idea+MySQL实现简单的用户登录功能_第2张图片

第三步:编写静态页面

结构:

Spring boot+idea+MySQL实现简单的用户登录功能_第3张图片

login.html

Spring boot+idea+MySQL实现简单的用户登录功能_第4张图片

test.html

Spring boot+idea+MySQL实现简单的用户登录功能_第5张图片

注意:这个标签要加一个斜杠,还有下面的,不加可能会报错,我就遇到了

第四步:编写实体类

Spring boot+idea+MySQL实现简单的用户登录功能_第6张图片

第五步:编写mapper类,数据库的操作

Spring boot+idea+MySQL实现简单的用户登录功能_第7张图片

第六步:编写service层 业务层

Spring boot+idea+MySQL实现简单的用户登录功能_第8张图片

第七步:controller层

Spring boot+idea+MySQL实现简单的用户登录功能_第9张图片

最后运行一下

Spring boot+idea+MySQL实现简单的用户登录功能_第10张图片

输入数据库里的用户名和密码

Spring boot+idea+MySQL实现简单的用户登录功能_第11张图片

恭喜你!spring boot 登录的功能就做好了

你可能感兴趣的:(spring,boot)