码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot整合SpringSecurity

时间:2021-04-06 14:26:35      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:uid   generate   src   artifact   rem   添加   项目   英文   innodb   

一、添加依赖

技术图片

 

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
    <version>2.4.4</version>
</dependency>

 

二、创建数据库表

DROP TABLE IF EXISTS `vhr`.`user`;
CREATE TABLE  `vhr`.`user` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(45) NOT NULL DEFAULT ‘‘ COMMENT 登录用户名,
  `password` varchar(255) NOT NULL DEFAULT ‘‘ COMMENT 登录密码,
  `enabled` tinyint(1) NOT NULL DEFAULT 0,
  `locked` tinyint(1) NOT NULL DEFAULT 0,
  `name` varchar(32) DEFAULT NULL COMMENT 姓名,
  `userface` varchar(255) DEFAULT NULL COMMENT 用户头像,
  `phone` varchar(11) DEFAULT NULL COMMENT 手机号码,
  `telephone` varchar(16) DEFAULT NULL COMMENT 固定电话,
  `address` varchar(255) DEFAULT NULL COMMENT 联系地址,
  `email` varchar(255) DEFAULT NULL COMMENT 电子邮箱,
  `remark` varchar(255) DEFAULT NULL COMMENT 备注,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `vhr`.`role`;
CREATE TABLE  `vhr`.`role` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `nameEn` varchar(45) NOT NULL DEFAULT ‘‘,
  `nameCn` varchar(45) NOT NULL DEFAULT ‘‘,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `vhr`.`user_role`;
CREATE TABLE  `vhr`.`user_role` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(10) unsigned NOT NULL DEFAULT 0,
  `rid` int(10) unsigned NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `FK_user_role_1` (`uid`),
  KEY `FK_user_role_2` (`rid`),
  CONSTRAINT `FK_user_role_1` FOREIGN KEY (`uid`) REFERENCES `user` (`id`),
  CONSTRAINT `FK_user_role_2` FOREIGN KEY (`rid`) REFERENCES `role` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `vhr`.`menu`;
CREATE TABLE  `vhr`.`menu` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `url` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ‘‘ COMMENT 请求路径规则,
  `path` varchar(64) DEFAULT NULL COMMENT 路由path,
  `component` varchar(64) DEFAULT NULL COMMENT 组件英文名称,
  `name` varchar(64) DEFAULT NULL COMMENT 组件中文名称,
  `iconCls` varchar(64) DEFAULT NULL COMMENT 菜单图标,
  `keepAlive` tinyint(1) NOT NULL DEFAULT 0 COMMENT 菜单切换时是否保活,
  `requireAuth` tinyint(1) NOT NULL DEFAULT 0 COMMENT 是否登录后才能访问,
  `pid` int(10) unsigned DEFAULT NULL COMMENT 父菜单Id,
  `enabled` tinyint(1) NOT NULL DEFAULT 1 COMMENT 是否可用,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `vhr`.`menu_role`;
CREATE TABLE  `vhr`.`menu_role` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `mid` int(10) unsigned NOT NULL DEFAULT 0,
  `rid` int(10) unsigned NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `FK_menu_role_1` (`mid`),
  KEY `FK_menu_role_2` (`rid`),
  CONSTRAINT `FK_menu_role_1` FOREIGN KEY (`mid`) REFERENCES `menu` (`id`),
  CONSTRAINT `FK_menu_role_2` FOREIGN KEY (`rid`) REFERENCES `role` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 技术图片

 三、启动项目测试

随便添加一个简单接口,网页url访问测试,我这里用的是之前的接口

技术图片

技术图片

 

 

默认用户名是user,默认密码在每次启动项目时随机生成  

Using generated security password: 0a98ecc8-779b-4dd7-86c6-1b39f6b77437

 

SpringBoot整合SpringSecurity

标签:uid   generate   src   artifact   rem   添加   项目   英文   innodb   

原文地址:https://www.cnblogs.com/mingforyou/p/14615809.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!