大家好,又见面了,我是你们的朋友全栈君。
//含有联合主键的映射
@Entity
@Getter
@Setter
@Table(name = "sign_table")
@IdClass(InfoLeadersId.class)
public class InfosLeaders extends BaseEntity implements Serializable {
@Id
@Column(name = "info_id")
private Long infoId;
@Id
@Column(name = "user_id")
private Long userId;
}
//联合主键类
@Getter
@Setter
public class InfoLeadersId implements Serializable {
private static final long serialVersionUID = 1L;
private Long infoId;
private Long userId;
@Override
public int hashCode() {
return Objects.hash(infoId, userId);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof InfoLeadersId) {
InfoLeadersId key = (InfoLeadersId) obj;
if (this.userId.equals(key.getUserId()) && this.infoId.equals(key.getInfoId())) {
return true;
}
}
return false;
}
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/148923.html原文链接:https://javaforall.cn