0

所以我们正在为我们的项目进行登录。我们遇到的问题是我们只在参数中得到 null 而不是我们输入的实际值。有人知道为什么吗?

控制器代码:

@RequestMapping(value = "/user/login",method = RequestMethod.POST)
public String logIn(@ModelAttribute("user") User user) {

 //Random code here

 return "redirect:/general/index.html";

}

看法:

<form:form id="header_login_form" method="POST"  ModelAttribute="user" action="/ProjectTeamF-1.0/user/login.html">
    <input path="username"class="input" placeholder="Email" />
    <input path="password" class="input" placeholder="Password" />
    <label class="checkbox">
    <input type="checkbox"> Aangemeld blijven</label>
    <button type="submit" class="btn">Aanmelden</button>
</form:form>
4

1 回答 1

0

您需要使用标签<form:input>而不是<input>为了让 Spring 绑定userModelAttribute。并替换ModelAttributecommandName

<form:form id="header_login_form" method="POST"  commandName="user" action="/ProjectTeamF-1.0/user/login.html">
    <form:input path="username"class="input" placeholder="Email" />
    <form:input path="password" class="input" placeholder="Password" />
    <label class="checkbox">
    <input type="checkbox"> Aangemeld blijven</label>
    <button type="submit" class="btn">Aanmelden</button>
</form:form>
于 2013-02-11T13:57:28.247 回答