SpringSecurity默認(rèn)登錄頁的使用示例教程
SpringSecurity的默認(rèn)登錄頁的使用
01 前期準(zhǔn)備
引入依賴
<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 啟動項目
啟動之后,會自動生成默認(rèn)密碼

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

- 默認(rèn)界面的賬號默認(rèn)user,密碼是Using generated security password隨機生成的
到此這篇關(guān)于SpringSecurity的默認(rèn)登錄頁的使用的文章就介紹到這了,更多相關(guān)SpringSecurity默認(rèn)登錄頁內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- springsecurity實現(xiàn)攔截器的使用示例
- SpringSecurity整合JWT的使用示例
- SpringSecurity攔截器鏈的使用詳解
- SpringSecurity實現(xiàn)權(quán)限認(rèn)證與授權(quán)的使用示例
- 使用SpringSecurity+defaultSuccessUrl不跳轉(zhuǎn)指定頁面的問題解決方法
- SpringSecurity入門使用教程
- springsecurity實現(xiàn)用戶登錄認(rèn)證快速使用示例代碼(前后端分離項目)
- Spring Security 使用 OncePerRequestFilter 過濾器校驗登錄過期、請求日志等操作
- Spring Security使用多種加密方式進(jìn)行密碼校驗的代碼示例
- 新版SpringSecurity5.x使用與配置詳解
相關(guān)文章
springboot從application.properties中注入list,?map方式
這篇文章主要介紹了springboot從application.properties中注入list,map方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-11-11
Intellij IDEA 2017.3使用Lombok及常用注解介紹
這篇文章主要介紹了Intellij IDEA 2017.3使用Lombok及常用注解介紹,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
阿里云部署SpringBoot項目啟動后被殺進(jìn)程的問題解析
這篇文章主要介紹了阿里云部署SpringBoot項目啟動后被殺進(jìn)程的問題,本文給大家分享問題原因所在及解決步驟,需要的朋友可以參考下2023-09-09
Java中BigDecimal除法使用不當(dāng)導(dǎo)致精度問題
本文主要介紹了Java中BigDecimal除法使用不當(dāng)導(dǎo)致精度問題,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11
Java之Swagger配置掃描接口以及開關(guān)案例講解
這篇文章主要介紹了Java之Swagger配置掃描接口以及開關(guān)案例講解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08

