SpringSecurity默認(rèn)登錄頁的使用示例教程
SpringSecurity的默認(rèn)登錄頁的使用
01 前期準(zhǔn)備
引入依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--mysql驅(qū)動(dòng)--> <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: (賬號(hào)) 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 啟動(dòng)項(xiàng)目
啟動(dòng)之后,會(huì)自動(dòng)生成默認(rèn)密碼
- Using generated security password: 8d97e198-138c-4093-9a5c-ac83e2dda426
- 這時(shí)候訪問接口被spring-security默認(rèn)攔截,必須登錄后才能訪問
- 默認(rèn)界面的賬號(hào)默認(rèn)user,密碼是Using generated security password隨機(jī)生成的
到此這篇關(guān)于SpringSecurity的默認(rèn)登錄頁的使用的文章就介紹到這了,更多相關(guān)SpringSecurity默認(rèn)登錄頁內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- springsecurity實(shí)現(xiàn)攔截器的使用示例
- SpringSecurity整合JWT的使用示例
- SpringSecurity攔截器鏈的使用詳解
- SpringSecurity實(shí)現(xiàn)權(quán)限認(rèn)證與授權(quán)的使用示例
- 使用SpringSecurity+defaultSuccessUrl不跳轉(zhuǎn)指定頁面的問題解決方法
- SpringSecurity入門使用教程
- springsecurity實(shí)現(xiàn)用戶登錄認(rèn)證快速使用示例代碼(前后端分離項(xiàng)目)
- Spring Security 使用 OncePerRequestFilter 過濾器校驗(yàn)登錄過期、請(qǐng)求日志等操作
- Spring Security使用多種加密方式進(jìn)行密碼校驗(yàn)的代碼示例
- 新版SpringSecurity5.x使用與配置詳解
相關(guān)文章
SpringBoot讀取properties中文亂碼解決方案
本文主要介紹了在Spring?Boot中讀取帶有中文字符串的application.properties文件時(shí)遇到亂碼問題的解決方案,具有一定的參考價(jià)值,感興趣的可以了解一下2024-12-12Java飛行記錄器JFR功能實(shí)現(xiàn)過程圖解
這篇文章主要介紹了Java飛行記錄器JFR功能實(shí)現(xiàn)過程圖解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05Spring Cloud Feign文件傳輸?shù)氖纠a
微服務(wù)中通常使用 Feign 作為服務(wù)消費(fèi)者,那么如何使用 Feign 接口傳輸文件呢?這篇文章主要介紹了Spring Cloud Feign文件傳輸?shù)氖纠a,感興趣的小伙伴們可以參考一下2018-06-06一文掌握Spring中循環(huán)依賴與三級(jí)緩存
這篇文章主要介紹了Spring中循環(huán)依賴與三級(jí)緩存,Spring通過三級(jí)緩存解決了循環(huán)依賴,其中一級(jí)緩存為單例池,二級(jí)緩存為早期曝光對(duì)象earlySingletonObjects,三級(jí)緩存為早期曝光對(duì)象工廠(singletonFactories),本文結(jié)合實(shí)例代碼介紹的非常詳細(xì),需要的朋友參考下吧2023-09-09Springboot項(xiàng)目異常處理及返回結(jié)果統(tǒng)一
這篇文章主要介紹了Springboot項(xiàng)目異常處理及返回結(jié)果統(tǒng)一,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下2022-08-08Java實(shí)現(xiàn)后臺(tái)發(fā)送及接收json數(shù)據(jù)的方法示例
這篇文章主要介紹了Java實(shí)現(xiàn)后臺(tái)發(fā)送及接收json數(shù)據(jù)的方法,結(jié)合實(shí)例形式分析了java針對(duì)json格式數(shù)據(jù)的傳輸與操作相關(guān)技巧,需要的朋友可以參考下2018-12-12詳解MyBatis resultType與resultMap中的幾種返回類型
本文主要介紹了MyBatis resultType與resultMap中的幾種返回類型,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下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)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-12-12