配置登录失败跳转地址, 修改WebSecurityConfig配置文件
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests().antMatchers("/").permitAll()
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
.anyRequest().authenticated()
.and().formLogin().loginPage("/user/login")
.failureUrl("/user/login?error").permitAll()
.defaultSuccessUrl("/").permitAll()
.and().logout().logoutSuccessUrl("/user/login").permitAll();
}
修改登录页面
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"><head>
<meta charset="UTF-8"/>
<title>登录页面</title>
</head>
<body>
<form action="/user/login" method="post">
<table>
<tr>
<p th:if="${param.error}" class="bg-danger">有错误,请重试</p>
</tr>
<tr>
<td>用户名:</td>
<td><input name="username" id="username" value=""/></td>
</tr>
<tr>
<td>密码:</td>
<td><input name="password" id="password" value=""/></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="submit"/></td>
</tr>
</table>
</form>
</body>
</html>