Spring Boot JPA 在实体中设置多个主键的方法
第一步:写一个包含主键色类PrimaryKey并实例化
@Data
public class UserPrimaryKey implements Serializable {
private Integer id;
private Integer userId;
}
第二步:在实体类中按照下面步骤设置
1.使用@IdClass。加在类上。
2.使用@Id。加在需要设置成主键的字段上。
@Data
@Entity
@Table(name = "sys_user")
@IdCl
原创
2021-05-26 14:16:18 ·
2162 阅读 ·
0 评论