我正在尝试在spring mvc中创建一个注册表单。 UserProfile模型负责注册,与Password模型有1对1关系,与Role模型有多对多的关系。
UserProfile模型:
@Entity
@Table(name="user_profile")
public class UserProfile {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="user_profile_id")
private Integer userProfileId;
@Column(name="user_name",length=30,unique=true,nullable=false)
private String userName;
@Column(name="first_name")
private String firstName;
@Column(name="last_name")
private String lastName;
@Column(name="sex")
private String sex;
@Column(name="contact")
private String contact;
@Column(name="image_path")
private String imagePath;
@Column(name="state")
private String state;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "role_join_profile",
joinColumns = { @JoinColumn(name = "user_profile") },
inverseJoinColumns = { @JoinColumn(name = "role") })
@Fetch(value = FetchMode.SUBSELECT)
private List<Role> role = new ArrayList<Role>();
@OneToOne(cascade = CascadeType.ALL,fetch=FetchType.EAGER)
@JoinColumn(name="password")
private Password password;
@OneToMany(mappedBy="postGiver",fetch=FetchType.EAGER)
@Fetch(value = FetchMode.SUBSELECT)
private List<DashBoard> dashBoardList;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "message_join_user",
joinColumns = { @JoinColumn(name = "user_profile") },
inverseJoinColumns = { @JoinColumn(name = "message_id") })
@Fetch(value = FetchMode.SUBSELECT)
private List<Message> messageList = new ArrayList<Message>();
+All attribute's getters & setters
}
角色模型:
@Entity
@Table(name="role")
public class Role {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="role_id")
private Integer roleId;
+All attribute's getters & setters
}
密码型号:
@Entity
@Table(name="password")
public class Password {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="password_id")
private Integer passwordId;
@Column(name="password")
private String password;
+All attribute's getters & setters
}
如果我发布与UserProfile模型相关的表单,则会显示以下错误
HTTP状态400 - 客户端发送的请求在语法上不正确。
它不会进入控制器的post方法。
当我尝试使用其他模型(如角色模型)时,它可以正常工作。
此UserProfile模型显示错误的问题是什么。
形式:
<form:form action="reg" method="POST" >
<input type="submit"/>**There is no field here cause i just want to hit
controller's method**
</form:form>
控制器的方法:
@RequestMapping(value="/reg",method = RequestMethod.POST)
public void reg(Model model,@ModelAttribute UserProfile userProfile){
System.out.print("sssssss");//this is not being printed,which should be
}