spring2.5注释型 + jpa + 数据库池的配置(3)
程序员文章站
2022-01-30 20:47:16
...
Person.java(实体文件)
package org.jinsheng.jpa.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity //声名为一个实体
@Table(name = "pjsh_person") //表名
public class Person
{
@Id //主键
private long id;
@Column //列 如果列与此实体属性不匹配应如此写 @Column(name="column name")
private String name;
@Column
private String username;
@Column
private String password;
@Column
private String sex;
@Column
private int age;
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getSex()
{
return sex;
}
public void setSex(String sex)
{
this.sex = sex;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
@Override
public String toString()
{
StringBuffer buf = new StringBuffer();
buf.append("ID:");
buf.append(this.id);
buf.append(";name:");
buf.append(this.name);
buf.append(";username:");
buf.append(this.username);
buf.append(";password:");
buf.append(this.password);
buf.append(";sex:");
buf.append(this.sex);
buf.append(";age:");
buf.append(this.age);
return buf.toString();
}
@Override
public boolean equals(Object obj)
{
if (obj instanceof Person)
{
Person person = (Person) obj;
if (((id == 0) && (person.getId() != 0))
|| (id != 0 && id != person.getId()))
{
return false;
}
return true;
}
return false;
}
@Override
public int hashCode()
{
Long id = getId();
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public Person clone()
{
Person person = new Person();
person.setId(id);
person.setAge(age);
person.setName(name);
person.setUsername(username);
person.setPassword(password);
person.setSex(sex);
return person;
}
}