广告
返回顶部
首页 > 资讯 > 后端开发 > Python >SpringBoot整合Security权限控制登录首页
  • 728
分享到

SpringBoot整合Security权限控制登录首页

SpringBoot整合Security登录SpringBootSecurity权限控制 2022-11-16 00:11:00 728人浏览 泡泡鱼

Python 官方文档:入门教程 => 点击学习

摘要

目录在 pom 文件中增加thymeleaf页面支持application.yml 配置文件login 页面controller目录下跳转配置UserController在 pom

在 pom 文件中增加thymeleaf页面支持

<!-- 引入页面模板 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

application.yml 配置文件

创建 resources 目录文件夹目录为: src/main/resources 并将其设置为 resource 资源目录, 在resources目录下创建 application.yml 配置文件

spring:
  thymeleaf:
    cache: false
    check-template: true
    check-template-location: true
    content-type: text/html
    enabled: true
    encoding: UTF-8
    mode: HTML5
    prefix: classpath:/templates/
    suffix: .html

在resources目录下创建 templates 文件目录, 并在该目录下创建 index.html 和 login.html 页面文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>SpringBoot Security Integration</title>
</head>
<body>
</body>
</html>

login 页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>登录页面</title>
</head>
<body>
<fORM action="" method="post">
    <table>
        <tr>
            <td>用户名:</td>
            <td><input name="username" id="username" value=""/></td>
        </tr>
        <tr>
            <td>密码:</td>
            <td><input name="passWord" id="password" value=""/></td>
        </tr>
        <tr>
            <td colspan="2"><input type="submit" value="submit" /></td>
        </tr>
    </table>
</form>
</body>
</html>

controller目录下跳转配置

在 java 源码目录下创建controller目录, 并在该目录下创建 HomeController/UserController 进行页面跳转配置


package com.edurt.controller;
import org.springframework.stereotype.Controller;
import org.springframework.WEB.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class HomeController {
    
    @RequestMapping(value = "/", method = RequestMethod.GET)
    String home() {
        return "index";
    }
}

UserController


package com.edurt.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value = "user")
public class UserController {
    
    @RequestMapping(value = "login", method = RequestMethod.GET)
    String login() {
        return "login";
    }
    
    @RequestMapping(value = "loGout", method = RequestMethod.GET)
    String logout() {
        return "login";
    }
}

以上就是SpringBoot整合Security权限控制登录首页的详细内容,更多关于SpringBoot整合Security登录的资料请关注编程网其它相关文章!

--结束END--

本文标题: SpringBoot整合Security权限控制登录首页

本文链接: https://www.lsjlt.com/news/172987.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作