Spring boot登录错误提示

登录错误提示

当用户输入信息,错误的时候
页面给出提示信息

使用Thymeleaf的if判断


<p style="color: red" th:text="${msg}" th:if="${not #strings.isEmpty(msg)}">p>

Spring boot登录错误提示_第1张图片
当msg不为空时,会显示p标签
Msg为Controller返回的登录信息

@Controller
public class LoginController {

//    @DeleteMapping
//    @PutMapping
//    @GetMapping

    //@RequestMapping(value = "/user/login",method = RequestMethod.POST)
    @PostMapping(value = "/user/login")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Map<String, Object> map, HttpSession session) {
        if (!StringUtils.isEmpty(username) && "123456".equals(password)) {
            //登陆成功,防止表单重复提交,可以重定向到主页
            session.setAttribute("loginUser", username);
            return "redirect:/main.html";
        } else {
            //登陆失败
            map.put("msg", "用户名密码错误");
            return "login";
        }

    }
}

你可能感兴趣的:(————Spring,Boot)