springboot集成springsecurity

springboot集成springsecurity

1.引入依赖

<dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-thymeleafartifactId>
dependency>
<dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-securityartifactId>
dependency>

2.配置用户名和密码

spring.security.user.name=admin
spring.security.user.password=admin

springboot集成springsecurity_第1张图片

3.创建一个controller和一个页面

springboot集成springsecurity_第2张图片

springboot集成springsecurity_第3张图片

DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<body>
<h1>Helloh1>
<p>我是登录后才可以看的页面p>
body>
html>
package com.yangjunbo.JPADemo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class SecurityController {
    @RequestMapping("/")
    public String index() {
        return "index";
    }
}

4.验证测试

springboot集成springsecurity_第4张图片
springboot集成springsecurity_第5张图片

你可能感兴趣的:(Mac开发,spring,boot,java,spring)