Java 提交Spring的HTML表单

Java 提交Spring的HTML表单,java,html,spring,forms,spring-mvc,Java,Html,Spring,Forms,Spring Mvc,我正在尝试使用Spring创建一个简单的登录页面。 我已经创建了教程[此处][1]中描述的表单 出于某种原因,当我点击submit按钮时,请求没有传递到控制器。(我在controllers方法的第一行设置了断点) 有人知道为什么吗 我的代码: 控制器: @RequestMapping(value="/login", method=RequestMethod.POST) public String login(@ModelAttribute(value="loginModel") LoginMod

我正在尝试使用Spring创建一个简单的登录页面。
我已经创建了教程[此处][1]中描述的表单
出于某种原因,当我点击submit按钮时,请求没有传递到控制器。(我在controllers方法的第一行设置了断点)
有人知道为什么吗

我的代码:
控制器:

@RequestMapping(value="/login", method=RequestMethod.POST)
public String login(@ModelAttribute(value="loginModel") LoginModel loginModel) {
    if(loginModel.getEmail().equals("null") || loginModel.getPassword().equals("null")) {
        return "Wrong user email or password";
    }
    return "result";
}
型号:

public class LoginModel {
    private String email;
    private String password;
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public LoginModel(String email, String password) {
        super();
        this.email = email;
        this.password = password;
    }
}
视图:

    <!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" href="css/login.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    </head>
    <body>
        <div class="form">     
          <ul class="tab-group">
            <li class="tab active"><a href="signup.html">Sign Up</a></li>
            <li class="tab"><a href="login.html">Log In</a></li>
          </ul>
          <div id="login">   
            <h1>Welcome Back!</h1>          
            <form action="#" th:action="@{/login}" th:object="${loginModel}" method="post">        
              <div class="field-wrap">
                <input type="email" required autocomplete="off" th:field="*{email}"/>
              </div>          
              <div class="field-wrap">
                <input type="password" required autocomplete="off" th:field="*{password}"/>
              </div>          
              <p class="forgot">
                <a href="#">Forgot Password?</a>
              </p>         
              <input type="submit" value="Log in" />       
            </form>
          </div>      
        </div>
    </body>
</html>

欢迎回来!

更新:
发现问题…

LoginModel类必须具有空构造函数

请删除@modeldattribute,然后重试。

为什么要修复它?@Sam这应该是一个comment@Sam-它没有解决问题-到底发生了什么?你得到了404错误还是别的什么?@AlanHay-我得到了与URL末尾的“#”相同的(干净的)视图