# 第一步 配置视图
~~~
@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>
~~~

