10、Springboot整合SpringSecurity
阿新 • • 發佈:2021-06-17
1、搭建Security的環境,新增pom,xml相關依賴
<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.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional></dependency>
2、新增靜態資原始檔和頁面
3、配置application.yml
spring:
thymeleaf:
cache: false
4、測試頁面跳轉的IndexController類
@Controller
public class IndexController {
@RequestMapping({"/","/index"})
public String index(){
return "index";
}
@RequestMapping(value = "/toLogin")
public String toLogin() {
return "views/login";
}
@RequestMapping(value = "/level1/{id}")
public String level1(@PathVariable("id") Integer id) {
return "views/level1/" + id;
}
@RequestMapping(value = "/level2/{id}")
public String level2(@PathVariable("id") Integer id) {
return "views/level2/" + id;
}
@RequestMapping(value = "/level3/{id}")
public String level3(@PathVariable("id") Integer id) {
return "views/level3/" + id;
}
}