SpringSecurity入門案例
建立項目
- 建立springboot項目
- 确定建立(什麼都不要配置)
配置SpringSecurity依賴
- 修改pom.xml,添加依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
Demo案例
- 建立controller層并建立java檔案
@RestController @RequestMapping("/test") public class TestController { @GetMapping("hello") public String add() { return "hello security"; } }
啟動測試
- 輸入位址
http://localhost:8081/test/lello
- 頁面跳轉緻http://localhost:8081/login表示配置成功
- 賬号預設為user,密碼在控制台中列印 * 輸入賬号密碼後進入原輸入位址頁面