SpringBoot整合Security權(quán)限控制登錄首頁
在 pom 文件中增加thymeleaf頁面支持
<!-- 引入頁面模板 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
application.yml 配置文件
創(chuàng)建 resources 目錄文件夾目錄為: src/main/resources 并將其設置為 resource 資源目錄, 在resources目錄下創(chuàng)建 application.yml 配置文件
spring: thymeleaf: cache: false check-template: true check-template-location: true content-type: text/html enabled: true encoding: UTF-8 mode: HTML5 prefix: classpath:/templates/ suffix: .html
在resources目錄下創(chuàng)建 templates 文件目錄, 并在該目錄下創(chuàng)建 index.html 和 login.html 頁面文件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>SpringBoot Security Integration</title> </head> <body> </body> </html>
login 頁面
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>登錄頁面</title> </head> <body> <form action="" method="post"> <table> <tr> <td>用戶名:</td> <td><input name="username" id="username" value=""/></td> </tr> <tr> <td>密碼:</td> <td><input name="password" id="password" value=""/></td> </tr> <tr> <td colspan="2"><input type="submit" value="submit" /></td> </tr> </table> </form> </body> </html>
controller目錄下跳轉(zhuǎn)配置
在 java 源碼目錄下創(chuàng)建controller目錄, 并在該目錄下創(chuàng)建 HomeController/UserController 進行頁面跳轉(zhuǎn)配置
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.edurt.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * HomeController * 描述 : HomeController * 作者 : qianmoQ * 版本 : 1.0 * 創(chuàng)建時間 : 2018-03-20 下午2:24 */ @Controller public class HomeController { /** * 首頁 * * @return 首頁頁面跳轉(zhuǎn) */ @RequestMapping(value = "/", method = RequestMethod.GET) String home() { return "index"; } }
UserController
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.edurt.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * UserController * 描述 : UserController * 作者 : qianmoQ * 版本 : 1.0 * 創(chuàng)建時間 : 2018-03-20 下午2:24 */ @Controller @RequestMapping(value = "user") public class UserController { /** * 用戶登錄 * * @return 用戶登錄頁面跳轉(zhuǎn) */ @RequestMapping(value = "login", method = RequestMethod.GET) String login() { return "login"; } /** * 用戶注銷退出 * * @return 用戶注銷退出頁面跳轉(zhuǎn) */ @RequestMapping(value = "logout", method = RequestMethod.GET) String logout() { return "login"; } }
以上就是SpringBoot整合Security權(quán)限控制登錄首頁的詳細內(nèi)容,更多關于SpringBoot整合Security登錄的資料請關注腳本之家其它相關文章!
- Springboot安全框架整合SpringSecurity實現(xiàn)方式
- springboot整合security和vue的實踐
- springboot整合springsecurity與mybatis-plus的簡單實現(xiàn)
- SpringBoot如何整合Springsecurity實現(xiàn)數(shù)據(jù)庫登錄及權(quán)限控制
- SpringBoot整合SpringSecurityOauth2實現(xiàn)鑒權(quán)動態(tài)權(quán)限問題
- Springboot詳解整合SpringSecurity實現(xiàn)全過程
- SpringBoot整合SpringSecurity實現(xiàn)JWT認證的項目實踐
- SpringBoot整合Spring?Security過濾器鏈加載執(zhí)行流程源碼分析(最新推薦)
- SpringBoot整合SpringSecurity和JWT和Redis實現(xiàn)統(tǒng)一鑒權(quán)認證
- SpringBoot整合SpringSecurity認證與授權(quán)
- SpringBoot整合Spring Security構(gòu)建安全的Web應用
相關文章
SpringSecurity的@EnableWebSecurity注解詳解
這篇文章主要介紹了SpringSecurity的@EnableWebSecurity注解詳解,@EnableWebSecurity是開啟SpringSecurity的默認行為,它的上面有一個Import注解導入了WebSecurityConfiguration類,就是往IOC容器中注入了WebSecurityConfiguration這個類,需要的朋友可以參考下2023-11-11Mybatis的TypeHandler加解密數(shù)據(jù)實現(xiàn)
在我們數(shù)據(jù)庫中有些時候會保存一些用戶的敏感信息,所以就需要對這些數(shù)據(jù)進行加密,那么本文就介紹了Mybatis的TypeHandler加解密數(shù)據(jù)實現(xiàn),感興趣的可以了解一下2021-06-06