我认为这不是标准的做法,所以任何提示都会有所帮助,这是我的代码:
@RequestMapping("/register")
public String register(Map<String, Object> map, @ModelAttribute("user") MyUser user) {
if(user.getLogin() == ""){
map.put("user", new MyUser());
}
else{
map.put("user", user);
map.put("result", userService.addMyUser(user));
}
return "register";
}
导致以下错误的原因:
org.hibernate.AssertionFailure:org.mypackage.MyUser条目中的null id (发生异常后不要刷新会话)
这是MyUser
类:
@Entity
@Table(name="MyUser")
public class MyUser{
@Id
@Column(name="idMyUser")
@GeneratedValue
private Integer id;
@Column(name="login")
private String login;
@Column(name="password")
private String password;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}