关于spring-boot的SpringSecurity(权限管理)的代码流程

1. 创建权限管理,先创建对应得数据库表。

2.引入该有的依赖

3.写yml文件

4.bean包

5.config

6.filter

接下来就是流程:mapper-service-impl


1. 创建权限管理,先创建对应得数据库表。

(1)三张基础表:用户,角色,权限表

(2)两张:用户-权限,角色-权限表

# 权限管理
# 用户
create table user
(
    id int primary key auto_increment,
    name varchar(20) not null unique ,
    password varchar(100) not null,
    nickname varchar(20),
    roleId int,
    state int default 1
);
insert into user values(null,'admin','123456','管理员',1,1);
# 角色
create table role
(
    id int primary key auto_increment,
    name varchar(20)
);
insert into role values(null,'用户管理');

# 权限
create table power
(
    id int primary key auto_increment,
    name varchar(20),
    url varchar(100)
);
insert into power values(null,'用户查询','/user/find');

# 用户-权限关联表
create table user_power
(
    id int primary key  auto_increment,
    user_id int ,//注意先写user
    power_id int,
    foreign key(user_id) references user(id),
    foreign key(power_id) references power(id)
);
insert into user_power values(null,1,6);


# 角色-权限关联表
create table role_power
(
    id int primary key auto_increment,
    role_id int,
    power_id int,
    foreign key(power_id) references power(id),
    foreign key(role_id) references role(id)
);
insert into role_power values(null,1,1);

2.引入该有的依赖

  也可以分为父子项目写按自己情况


    <!--引入ioc依赖-->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>2.0.19</version>
        </dependency>
    </dependencies>
  <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifa
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值