NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
# 第一步 配置视图 ~~~ @Configuration public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override public void configure(HttpSecurity http) throws Exception { http.formLogin()//设置自定义的登录页面 .loginPage("/login.html")//登录页面设置 .loginProcessingUrl("/user/login")//登录访问的路径Security 的 .defaultSuccessUrl("/edu").permitAll() //登录成功,跳转路径 .and().authorizeRequests()//设置被保护的路径 .antMatchers("/").permitAll()//设置不需要验证的路径 .anyRequest().authenticated()//设置所有路径都可以访问 .and().csrf().disable();//关闭csrf防护 } } ~~~ # 第二步编写试图 ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form action="/user/login" method="post"> 用户名: <input type="text" name="username"> <br> 密码: <input type="text" name="password"> <br> <input type="submit" value="登录"> </form> </body> </html> ~~~ ![](https://img.kancloud.cn/73/69/7369b883191813d8ab89a93f3b1e5745_401x108.png)