springboot+springsecurity+thymeleaf自定义登录校验信息问题

当用户不存在或密码错误如何自定义异常信息并在搞thymeleaf页面获取显示信息

比如在控制器代码如下

@Controller
public class ThymeleafController {
    @RequestMapping("/login")
    public String helloThymeleaf(Model model) {
       if(登录正确){
       }else{
       {
            model.addAttribute("myerror", "登录失败,失败原因……");
       }
        return "index";
    }

在html中

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>登录提示</title>
</head>
<body>
<p th:text="${myerror}">登录结果提示</p>
</body>
</html>

如果答案对你有用,记得采纳