购物网站7:用户/顾客的信息---用户---联系信息---性别

@Entity
public class Buyer implements Serializable{
 private static final long serialVersionUID = 8394979715028899027L;
 /** 用户名 **/
 private String username;//只允许字母/数字/下划线
 /** 密码 **/
 private String password;//采用MD5加密
 /** 真实姓名 **/
 private String realname;
 /** 电子邮箱 **/
 private String email;
 /** 性别 **/
 private Gender gender=Gender.MAN;
 /** 联系信息 **/
 private ContactInfo contactInfo;
 /** 是否启用 **/
 private Boolean visible=true;
 /** 注册时间 **/
 private Date regTime = new Date();
 
 @Temporal(TemporalType.TIMESTAMP) @Column(nullable=false)
 public Date getRegTime() {
  return regTime;
 }

 public void setRegTime(Date regTime) {
  this.regTime = regTime;
 }

 public Buyer(){}
 
 public Buyer(String username){
  this.username = username;
 }
 
 public Buyer(String username, String password) {
  this.username = username;
  this.password = password;
 }
 
 public Buyer(String username, String password, String email) {
  this.username = username;
  this.password = password;
  this.email = email;
 }
 
 @Id @Column(length=18)
 public String getUsername() {
  return username;
 }
 public void setUsername(String username) {
  this.username = username;
 }
 @Column(length=32,nullable=false)
 public String getPassword() {
  return password;
 }
 public void setPassword(String password) {
  this.password = password;
 }
 @Column(length=8)
 public String getRealname() {
  return realname;
 }
 public void setRealname(String realname) {
  this.realname = realname;
 }
 @Column(length=50,nullable=false)
 public String getEmail() {
  return email;
 }
 public void setEmail(String email) {
  this.email = email;
 }
 @Enumerated(EnumType.STRING) @Column(nullable=false,length=5)
 public Gender getGender() {
  return gender;
 }
 public void setGender(Gender gender) {
  this.gender = gender;
 }
 @OneToOne(cascade=CascadeType.ALL)
 @JoinColumn(name="contactid")
 public ContactInfo getContactInfo() {
  return contactInfo;
 }
 public void setContactInfo(ContactInfo contactInfo) {
  this.contactInfo = contactInfo;
 }
 @Column(nullable=false)
 public Boolean getVisible() {
  return visible;
 }
 public void setVisible(Boolean visible) {
  this.visible = visible;
 }
 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result
    + ((username == null) ? 0 : username.hashCode());
  return result;
 }
 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  final Buyer other = (Buyer) obj;
  if (username == null) {
   if (other.username != null)
    return false;
  } else if (!username.equals(other.username))
   return false;
  return true;
 }
 
}

 

-----------------------------------------------------------

 

@Entity
public class ContactInfo implements Serializable{
 private static final long serialVersionUID = -4336182674133849896L;
 private Integer contactid;
 /** 地址 **/
 private String address;
 /** 邮编 **/
 private String postalcode;
 /** 座机 **/
 private String phone;
 /** 手机 **/
 private String mobile;
 /** 所属用户 **/
 private Buyer buyer;
 @Id @GeneratedValue
 public Integer getContactid() {
  return contactid;
 }
 public void setContactid(Integer contactid) {
  this.contactid = contactid;
 }
 @Column(length=100,nullable=false)
 public String getAddress() {
  return address;
 }
 public void setAddress(String address) {
  this.address = address;
 }
 @Column(length=6)
 public String getPostalcode() {
  return postalcode;
 }
 public void setPostalcode(String postcode) {
  this.postalcode = postcode;
 }
 @Column(length=20)
 public String getPhone() {
  return phone;
 }
 public void setPhone(String phone) {
  this.phone = phone;
 }
 @Column(length=11)
 public String getMobile() {
  return mobile;
 }
 public void setMobile(String mobile) {
  this.mobile = mobile;
 }
 @OneToOne(mappedBy="contactInfo",cascade=CascadeType.REFRESH)
 public Buyer getBuyer() {
  return buyer;
 }
 public void setBuyer(Buyer buyer) {
  this.buyer = buyer;
 }
 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result
    + ((contactid == null) ? super.hashCode() : contactid.hashCode());
  return result;
 }
 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  final ContactInfo other = (ContactInfo) obj;
  if (contactid == null) {
   if (other.contactid != null)
    return false;
  } else if (!contactid.equals(other.contactid))
   return false;
  return true;
 }
 
}

 

 

----------------------------------------------------------------

 

public enum Gender {
 MAN{
  public String getName(){return "男";}
 },WOMEN{
  public String getName(){return "女";}
 };
 public abstract String getName();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值