🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
Spring Security 默认的登录页面为 http://localhost:8080/login ,如下。 ![](https://img.kancloud.cn/51/3f/513f5a28acfad272a414afbcf178b19e_2064x436.png) 我们可以自定义登录页面。 <br/> 步骤如下: **1. 引入模板引擎** ```java <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> ``` **2. controller层** ```java @Controller public class IndexController { @RequestMapping("/to/login") public String login() { return "login"; } } ``` **3. 放行登录请求和静态资源请求** ```java @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/layui/**", "/to/login") //配置请求路径 .permitAll() //antMatchers方法指定的URL无需保护,允许通过。 .anyRequest() //其他请求 .authenticated(); //需要认证 } } ``` **4. 测试,访问地址 http://localhost:8080/to/login 即可到自定义的登录页面**