第一步:在resources/templates下创建login.html
登录页面
第二步:修改SpringSecurity配置文件
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin() //表单登录
.usernameParameter("username123")
.passwordParameter("password234")
.loginPage("/openLogin") //设置登录页面对应的地址,默认是/login
.loginProcessingUrl("/userLogin") //设置用户登录时请求的地址,默认是/login
.and()
.authorizeRequests()
//授权
.antMatchers("/openLogin").anonymous()//toLogin放行:不需要拦截,可以随便访问
.antMatchers("/**/*.css","/**/*.js","/imgs/**").permitAll()//放行静态资源
.anyRequest().authenticated()//其它请求都必须认证后才能访问
.and()
//关闭防火墙:为了保证完整流程可用关闭CSRF安全协议
.csrf().disable();
}