使用hibernate在数据库中保存数据
Saving data in database using hibernate
我目前正在为最后一年开发一个项目。
我有两个网页,第一个包含用户的个人详细信息,第二个包含用户的专业详细信息。
请指导我,如果我应该为两个页面都有一个 pojo class 或为每个页面分开。
也让我知道我的数据库应该如何设计例如:两个页面的两个单独的 table 或只有一次 table 有列来映射两个页面的数据。
还建议我是否应该在将用户重定向到他的专业页面之前保存第一页中输入的数据(验证后),或者我应该将两个页面的数据一起保存在第二页中。
1.According 对我来说,您应该为用户和专业人士提供单独的 pojo 类。
2.Also,应该有user和professional两个表。
3.You 可以先保存用户的保存详细信息,然后将用户重定向到其他专业页面,然后填写专业的必填详细信息。
请仔细阅读下面的详细信息。
@Entity
@Table(name = "user")
public class User {
private Long id;/*should auto generate with auto increment*/
private String firstName;
private String lastName;
private String userName;
private String mobileNumber;/*(change according to your requirement)*/
private String email1;
private String email2;
/*getters and setters*/
/*specify not null fields according to your requirement*/
}
@Entity
@Table(name = "professional")
public class Professional {
private Long id;/*should auto generate with auto increment*/
private User userId;/*one to one mapping*/
private Boolean whetherProfessional;
private String areaOfExpertise;
/*other fields according to your requirement*/
/*getters and setters*/
/*specify not null fields according to your requirement*/
}
我目前正在为最后一年开发一个项目。
我有两个网页,第一个包含用户的个人详细信息,第二个包含用户的专业详细信息。
请指导我,如果我应该为两个页面都有一个 pojo class 或为每个页面分开。
也让我知道我的数据库应该如何设计例如:两个页面的两个单独的 table 或只有一次 table 有列来映射两个页面的数据。
还建议我是否应该在将用户重定向到他的专业页面之前保存第一页中输入的数据(验证后),或者我应该将两个页面的数据一起保存在第二页中。
1.According 对我来说,您应该为用户和专业人士提供单独的 pojo 类。 2.Also,应该有user和professional两个表。 3.You 可以先保存用户的保存详细信息,然后将用户重定向到其他专业页面,然后填写专业的必填详细信息。
请仔细阅读下面的详细信息。
@Entity
@Table(name = "user")
public class User {
private Long id;/*should auto generate with auto increment*/
private String firstName;
private String lastName;
private String userName;
private String mobileNumber;/*(change according to your requirement)*/
private String email1;
private String email2;
/*getters and setters*/
/*specify not null fields according to your requirement*/
}
@Entity
@Table(name = "professional")
public class Professional {
private Long id;/*should auto generate with auto increment*/
private User userId;/*one to one mapping*/
private Boolean whetherProfessional;
private String areaOfExpertise;
/*other fields according to your requirement*/
/*getters and setters*/
/*specify not null fields according to your requirement*/
}