hibernate重写equals方法
public class User {
private Integer id;
private String username;
private String password;
private Integer age;
public User() {
super();
}
public User(Integer id, String username, String password, Integer age) {
super();
this.id = id;
this.username = username;
this.password = password;
this.age = age;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
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 Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public boolean equals(Object obj) {
if(obj==null)return false;
if(this==obj)return true;
if(obj instanceof User) {
User u = (User) obj;
return this.getId()==u.getId()
&&this.getUsername().equals(u.getUsername())
&&this.getPassword().equals(u.getPassword())
&&this.getAge()==u.getAge();
}
return false;
}