SpringSecurity默認登錄頁的使用示例教程
SpringSecurity的默認登錄頁的使用
01 前期準備
引入依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--mysql驅(qū)動-->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<!--模塊化插件配置類-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--mybatisplus依賴-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!--spring-security依賴-->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>配置系統(tǒng)文件
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/(需要連接的數(shù)據(jù)庫)?userSSL=false;serverTimezone=Asia/Shanghai
username: (賬號)
password: (密碼)
mvc:
pathmatch:
matching-strategy: ant_path_matcher
mybatis-plus:
config-locations: classpath:mapper/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl配置掃描包
@SpringBootApplication
@MapperScan("com.example.demo.mapper")
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}02 編寫測試接口
測試類
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Category {
@TableId
private Long categoryId;
private String categoryName;
private String categoryPicture1;
private String categoryPicture2;
}測試用的控制層接口
@RestController
@RequestMapping("category")
public class CategoryController {
@Autowired
private ICategoryService iCategoryService;
@GetMapping("all")
public GetData selectAll(){
List<Category> categories=iCategoryService.list();
GetData getData = new GetData(200,"查詢成功",categories);
return getData;
}
@GetMapping("byId")
public GetData selectDetail(Long id){
Category category=iCategoryService.getById(id);
GetData getData = new GetData(200,"查詢成功",category);
return getData;
}
}03 啟動項目
啟動之后,會自動生成默認密碼

- Using generated security password: 8d97e198-138c-4093-9a5c-ac83e2dda426
- 這時候訪問接口被spring-security默認攔截,必須登錄后才能訪問

- 默認界面的賬號默認user,密碼是Using generated security password隨機生成的
到此這篇關(guān)于SpringSecurity的默認登錄頁的使用的文章就介紹到這了,更多相關(guān)SpringSecurity默認登錄頁內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- springsecurity實現(xiàn)攔截器的使用示例
- SpringSecurity整合JWT的使用示例
- SpringSecurity攔截器鏈的使用詳解
- SpringSecurity實現(xiàn)權(quán)限認證與授權(quán)的使用示例
- 使用SpringSecurity+defaultSuccessUrl不跳轉(zhuǎn)指定頁面的問題解決方法
- SpringSecurity入門使用教程
- springsecurity實現(xiàn)用戶登錄認證快速使用示例代碼(前后端分離項目)
- Spring Security 使用 OncePerRequestFilter 過濾器校驗登錄過期、請求日志等操作
- Spring Security使用多種加密方式進行密碼校驗的代碼示例
- 新版SpringSecurity5.x使用與配置詳解
相關(guān)文章
SpringBoot讀取properties中文亂碼解決方案
本文主要介紹了在Spring?Boot中讀取帶有中文字符串的application.properties文件時遇到亂碼問題的解決方案,具有一定的參考價值,感興趣的可以了解一下2024-12-12
Spring Cloud Feign文件傳輸?shù)氖纠a
微服務(wù)中通常使用 Feign 作為服務(wù)消費者,那么如何使用 Feign 接口傳輸文件呢?這篇文章主要介紹了Spring Cloud Feign文件傳輸?shù)氖纠a,感興趣的小伙伴們可以參考一下2018-06-06
Springboot項目異常處理及返回結(jié)果統(tǒng)一
這篇文章主要介紹了Springboot項目異常處理及返回結(jié)果統(tǒng)一,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的朋友可以參考一下2022-08-08
Java實現(xiàn)后臺發(fā)送及接收json數(shù)據(jù)的方法示例
這篇文章主要介紹了Java實現(xiàn)后臺發(fā)送及接收json數(shù)據(jù)的方法,結(jié)合實例形式分析了java針對json格式數(shù)據(jù)的傳輸與操作相關(guān)技巧,需要的朋友可以參考下2018-12-12
詳解MyBatis resultType與resultMap中的幾種返回類型
本文主要介紹了MyBatis resultType與resultMap中的幾種返回類型,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-09-09
解決Eclipse/STS中出現(xiàn)Resource is out of sync with the file system
今天小編就為大家分享一篇關(guān)于解決Eclipse/STS中出現(xiàn)Resource is out of sync with the file system的異常問題,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-12-12

