联合主键注解「建议收藏」

联合主键注解「建议收藏」含有联合主键的映射 Entity Getter Setter Table name sign table IdClass InfoLeadersI class public class InfosLeaders extends BaseEntity implements Serializable Id Column name

//含有联合主键的映射
@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;
}
}
编程小号
上一篇 2025-03-14 20:57
下一篇 2025-02-22 15:33

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/hz/137206.html