Springboot+SpringSecurity权限控制学习笔记(一)项目的创建

涉及到的技术栈:
Springboot
SpringSecurity
jwt
vue
axios
vue-cli
vuex
定时任务:xxl-job
aop

项目完整功能

  1. 登录
  2. 注销
  3. 动态拦截url请求(根据权限控制访问内容)
  4. 用户管理模块(增删改查)
  5. 角色管理模块(增删改查)
  6. 菜单管理模块(增删改查)
  7. 登录验证中增加额外数据(IP,MAC,验证码等)
  8. 其他(后期添加定时任务,Aop等登录日志以及操作日志)

Spring-Security与shiro对比

Shiro比Security更容易使用
Security比较有名
Security有更多的社区支持
Security对Spring支持较好
Shiro功能强大、简单、灵活。是Apache下的项目比较可靠,且不跟任何容器绑定,可以独立运行。

本笔记所用环境 Springboot2.x + SpringSecurity5.x + Mybatis/Mybatis-plus

需求分析:

登录页面
login.html
主页
main.html
用户管理
users.html
角色管理
roles.html
菜单管理
menus.html
其他管理
others.html
退出登录
logout

/login.html /login不用登录即可访问
user.html roles.html 普通用户登录可访问
menus.html others.html只有admin可以访问

创建项目

定义项目名和包名 选择java8
选择依赖,先选这几项,然后点Finish

在resources下面创建目录public,在其中创建login.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
</head>
<body>
<form action="/login" method="post">
    <p>
        <label for="username">用户名</label>
        <input type="text" id="username" name="username">
    </p>
    <p>
        <label for="password">密码</label>
        <input type="password" id="password" name="password">
    </p>
    <p><input type="submit" value="登录" /></p>
</form>
</body>
</html>

新建templates文件夹,在其中创建home.html users.html roles.html menus.html other.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台首页</title>
</head>
<body>
<h1>登录成功</h1>
<ul>
    <li><a href="/users">用户管理</a></li>
    <li><a href="/roles">角色管理</a></li>
    <li><a href="/menus">菜单管理</a></li>
    <li><a href="/others">其他管理</a></li>
    <li><a href="/logout">退出登录</a></li>
</ul>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
</head>
<body>
<h1>用户管理</h1>

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>角色管理</title>
</head>
<body>
<h1>角色管理</h1>

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>菜单管理</title>
</head>
<body>
<h1>菜单管理</h1>

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>其他管理</title>
</head>
<body>
<h1>其他管理</h1>

</body>
</html>

##新建controller.SecurityController控制器

package com.xb.rbac.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class SecurityController {
    @GetMapping({"/home","/"})
    public String home(){
        return "home";
    }
    @GetMapping("/users")
    public String users(){
        return "users";
    }
    @GetMapping("/menus")
    public String menus(){
        return "menus";
    }
    @GetMapping("/roles")
    public String roles(){
        return "roles";
    }
    @GetMapping("/others")
    public String others(){
        return "others";
    }
    @GetMapping("/error")
    public String error(){
        return "error";
    }
}

项目目录结构

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值