springBoot+MyBatis实现简单的登录
2020-04-25 08:43
435 查看
前言
使用工具:idea、MySQL
技术:spring Boot
创建数据库及测试表
-- 创建数据库 CREATE DATABASE IF NOT EXISTS shoop DEFAULT CHARSET utf8 COLLATE utf8_general_ci; -- 创建一个测试用的数据表 create table test_user( userId int auto_increment primary key, userName varchar(200), userPass varchar(200) )
实体类(entity)
public class Users { private Integer userId; private String userName; private String userPass; //省略Getter和Setter方法 }
接口(mapper)
@Mapper public interface UsersMapper { //因为用户是唯一的,所以可以直接使用实体类并不用List<实体类>这种 public Users select(Users users); }
myBatis配置文件(xml)
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.springboot.mapper.UsersMapper"> <select id="select" resultType="com.springboot.entity.Users"> select userName,userPass from test_user where userName=#{userName} and userPass=#{userPass} </select> </mapper>
业务层(service)
public interface IUsersService { //因为用户是唯一的,所以可以直接使用实体类并不用List<实体类>这种 public Users select(Users users); }
业务实现层(impl)
@Service public class UserServiceImpl implements IUsersService { @Resource UsersMapper mapper; @Override public Users select(Users users) { return mapper.select(users); } }
逻辑控制层(controller)
@RequestMapping("/Users") @Controller public class UsersController { @Resource IUsersService service; @RequestMapping("login") public String login(){ return "/admin/login"; } @RequestMapping("/select") public String select(Users users){ Users usersList = service.select(users); if(usersList != null ) { return "/admin/welcome"; } return "/admin/login"; } }
登录页面
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>用户登录</title> </head> <style> #login{ position: relative; top:200px; left: 600px; } </style> <body> <form action="/Users/select" method="post"> <div id="login"> 账户:<input type="text" name="userName"> <br/> 密码:<input type="text" name="userPass"> <br/> <input type="submit" value="登录"> </div> </form> </div> </body> </html>
以上就是用户登录的一个简单实例,项目源码https://pan.baidu.com/s/1Suc6iYCP7vOWXXAU-vupiw提取码:45vr
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- 使用IDEA创建Spring Boot项目, 整合Mybatis ,连接MySql数据库,实现简单的登录注册功能
- 微信小程序+SpringBoot+mybatis+MySQL实现简单的登录
- springboot+springsecurity+mybatis+thymeleaf实现用户登录和权限过程中的坑
- 用shiro+springboot+mybatis实现禁止账号重复登录
- SpringBoot入门——整合mybatis的增删改简单实现
- springboot+mybatis实现登录功能,返回json
- springmvc+mybatis+sql server实现简单登录功能【转】
- spring boot+mvc+mybatis+netty-sokey.io+html+js实现简单即时通讯聊天系统
- SpringBoot整合MybatisPlus的简单教程实现(简单整合)
- Springboot+mybatis实现web的简单增加,删除和查找功能
- springmvc+mybatis+sql server实现简单登录功能【转】
- Spring boot +Mybatis 实现多数据源(一:最简单版本)
- springmvc+mybatis+sql server实现简单登录功能
- 基于SpringBoot简单实现SpringAop+Redis+cookie 单点登录 和 用户登录检测
- springmvc+mybatis+sql server实现简单登录功能
- Springboot+mybatis+MySQL实现简单的多表查询
- spring boot 与shiro实战(四)整合MyBatis实现登录
- 四步教你SpringBoot+Mybatis-plus分页插件(简单实现)
- springmvc+mybatis+sql server实现简单登录功能【转】
- springmvc+mybatis+sql server实现简单登录功能【转】