私は2つのエンティティクラスを持っています:UserとAddress Userクラス:他の多くのプロパティと関連するクラスアドレスがあります
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ページとコントローラークラスで必要な変更. 助けてください。