我有两个实体类:用户和地址用户类:它有许多其他属性以及相关的类地址
Entity
@Table(name = "T_USER_DETAILS")
public class User {
//@GenericGenerator(name = "generator",strategy = "sequence-identity",parameters = { @Parameter(name = "sequence",value = "USER_ID_SEQ")} )
@GenericGenerator(name = "generator",strategy = "increment")
@Id
@GeneratedValue(generator = "generator")
@Column(name = "USER_ID")
private int userid;
@Column(name = "USER_FIRSTNAME")
private String firstname;
@Column(name = "USER_AGE")
private int age;
//creating many to one relationship between address class and student class
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "ADDRESS_ID")
private Address address;
这是地址类,它也是一个实体
@Entity
@Table(name = "T_ADDRESS_DETAILS")
public class Address {
@GenericGenerator(name = "idgenerator", strategy = "increment")
@Id
@GeneratedValue(generator = "idgenerator")
@Column(name = "ADDRESS_ID")
private int addressId;
@Column(name = "ADDRESS_LINE1")
private String address_line1;
@Column(name = "ADDRESS_LINE2")
private String address_line2;
在我的表单中,我正在为用户类创建一个命令 bean,并将其绑定到我的控制器类中:
<form:form method = "post" action = "register.html" commandName = "newUser">
<br>
<h2><i>Create new account</i></h2>
<br>
Enter the firstname<br>
<input type = "text" size = "30" name = "firstname">
<font color = "red"> <form:errors path = "firstname" cssClass = "error"/></font><br>
Enter the lastname<br>
<input type = "text" size = "30" name = "lastname">
<font color = "red"> <form:errors path = "lastname" cssClass = "error"/></font><br>
Enter the password<br>
<input type = "password" size = "30" name = "password">
<font color = "red"> <form:errors path = "password" cssClass = "error"/></font><br>
Enter the Email Id<br>
<input type = "text" size = "30" name = "emailId">
<font color = "red"><form:errors path = "emailId" cssClass = "error"/><br></font>
Enter the phone number<br>
<input type = "text" size = "30" name = "phonenumber">
<font color = "red"><form:errors path = "phonenumber" cssClass = "error"/></font><br>
Enter the age<br>
<input type = "text" size = "30" name = "age"/>
<font color = "red"><form:errors path = "age" cssClass = "error"/></font><br><br>
Enter the Address<br>
<input type = "textbox" name = "address" size = "30">
<font color = "red"><form:errors path = "address" cssClass = "error"/></font><br>
<div align = "center">
<input type = "submit" name = "submit" value = "submit">
控制器:
@RequestMapping(method = RequestMethod.POST)
public String register(@ModelAttribute("newUser") User user,BindingResult result,Model model,HttpSession session,HttpServletRequest request) //retrieve the backing bean with in the user attribute
{
..
}
我的问题是如何分配我想从城市、州、国家等表单发送的地址类的属性......我需要在我的 jsp 页面和我的控制器类中做哪些更改。请帮忙。