springboot jpa 复合主键


https://blog.csdn.net/wyc_cs/article/details/9031991

 

创建一个复合主键类

public class LevelPostMultiKeysClass  implements Serializable{
private Integer levelId;
private Integer postId;

public LevelPostMultiKeysClass() {
}

public LevelPostMultiKeysClass(Integer levelId, Integer postId) {
this.levelId = levelId;
this.postId = postId;
}

@Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((levelId == null) ? 0 : levelId.hashCode());
result = PRIME * result + ((postId == null) ? 0 : postId.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 LevelPostMultiKeysClass other = (LevelPostMultiKeysClass)obj;
if(levelId == null){
if(other.levelId != null){
return false;
}
}else if(!levelId.equals(other.levelId)){
return false;
}
if(postId == null){
if(other.postId != null){
return false;
}
}else if(!postId.equals(other.postId)){
return false;
}
return true;
}

}

 

 

 

 

 





免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM