11、SpringBoot集成SpringSecurity实战:数据库方式配置用户

前言

之前文章中,用户是在内存中配置的,接下来将用户信息存放到数据库中,然后从数据库读取用户信息。

表设计

这里会设计到用户,角色,权限表
*

创建用户表

DROP TABLE IF EXISTS sys_user;
CREATE TABLE sys_user (
  id char(19) COLLATE utf8mb4_general_ci NOT NULL COMMENT '主键id',
  nick_name varchar(64) COLLATE utf8mb4_general_ci NOT NULL COMMENT '昵称',
  mobile char(11) COLLATE utf8mb4_general_ci NOT NULL COMMENT '手机号',
  username varchar(64) COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户名',
  password varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '密码',
  user_face varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '头像',
  is_disabled tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否禁用,0:否,1:是',
  is_locked tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否锁定,0:否,1:是',
  is_expired tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否过期,0:否,1:是',
  is_credentials_expired tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '凭证是否过期,0:否,1是',
  create_time datetime NOT NULL COMMENT '创建时间',
  update_time datetime NOT NULL COMMENT '更新时间',
  is_deleted tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除,0:未删除,1:删除',
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='系统用户';

导入测试用户,密码是通过加密过后的(123)

INSERT INTO sys_user VALUES ('1', '系统管理员', '13821856321', 'admin', '$2a$10$oE39aG10kB/rFu2vQeCJTu/V/v4n6DRR0f8WyXRiAYvBpmadoOBE.', 'https://liuym-edu.oss-cn-beijing.aliyuncs.com/avatar/default/9e7fbeaa-6f50-4aaa-8207-73cb4ec3d1f2.jpg', 0, 0, 0, 0, '2021-5-5 11:48:04', '2021-5-5 11:48:06', 0);
INSERT INTO sys_user VALUES ('2', '普通用户', '15667056321', 'user', '$2a$10$oE39aG10kB/rFu2vQeCJTu/V/v4n6DRR0f8WyXRiAYvBpmadoOBE.', 'https://liuym-edu.oss-cn-beijing.aliyuncs.com/avatar/default/9e7fbeaa-6f50-4aaa-8207-73cb4ec3d1f2.jpg', 0, 0, 0, 0, '2021-5-17 23:01:02'

版权声明:本文不是「本站」原创文章,版权归原作者所有 | 原文地址: