Java SpringBoot学习笔记 34(SpringSecurity环境搭建)
来自B站【狂神说Java】SpringBoot最新教程IDEA版通俗易懂
1、知名的安全框架
shiro、SpringSecurity
2、新建项目

3. 导入素材
4. application.yml
spring:
thymeleaf:
cache: false
5. 测试Controller
注:先注释掉 security 依赖,否则测试时会跳转到登录页面
<dependencies>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
package com.example.springboot06security.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class RouterController {
@RequestMapping({"/", "/index"})
public String index() {
return "index";
}
@RequestMapping("toLogin")
public String toLogin() {
return "views/login";
}
@RequestMapping("/{level}/{id}")
public String level1(@PathVariable("level") String level, @PathVariable("id") int id) {
return "views/" + level + "/" + id;
}
}
浙公网安备 33010602011771号