Spring Boot Security(二)
Spring Security 配合 Thymeleaf 使用
注:Thymeleaf H5标注头:
xmlns:th="https://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
且 pom.xml 中
org.springframework.boot
spring-boot-starter-thymeleaf
org.thymeleaf.extras
thymeleaf-extras-springsecurity5
一、登录页面
1、记住我
- 在 Spring Security 中开启 rememberMe;
- 登录验证表单中需携带 remember-me。
2、退出登录
-
在 Spring Security 中进行登出配置
// 登出配置 http.logout() .logoutUrl("/logout") .invalidateHttpSession(true) .logoutSuccessUrl("/login") .permitAll() .and() .csrf() .disable(); -
向 logoutUrl 发送 post 请求即可
二、主页面
3、针对不同用户(权限)显示不同界面,利用 thymeleaf 模板引擎来实现
请先登录登录
你好!
您有ADMIN权限
您有ADMIN权限