第一步:写一个包含主键色类PrimaryKey并实例化
@Data
public class UserPrimaryKey implements Serializable {
private Integer id;
private Integer userId;
}
第二步:在实体类中按照下面步骤设置
1.使用@IdClass。加在类上。
2.使用@Id。加在需要设置成主键的字段上。
@Data
@Entity
@Table(name = "sys_user")
@IdClass(UserPrimaryKey.class)
@EqualsAndHashCode(callSuper = true)
@DynamicUpdate
public class SysUserEntity{
/**
* @description 主键
*/
@Id
@Column(name = "id", nullable = false)
private Integer id;
/**
* @description 主键
*/
@Id
@Column(name = "user_id", nullable = false)
private Integer userId;
}