两个实体类,Album类(一)对PictureList类(多)
- 下面是Album类
1、@OneToMany和@JoinColumn注解只能放在私有属性下面
2、JoinColumn中的name为“多”对象的外键名称
3、两者的联系是通过List对象联系的
@Entity
@Data
public class Album {
@GeneratedValue
@Id
private Integer id;
private String albumCover;
private String albumTitle;
private String albumDescription;
private Integer likes;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE)
@JoinColumn(name = "picture_id")
private List<PictureList> pictureList = new ArrayList<>();
public Album() {
}
@Entity
@Data
public class PictureList {
@GeneratedValue
@Id
private Integer id;
private String pictureTitle;
private String pictureRoad;
public PictureList(String pictureTitle, String pictureRoad) {
this.pictureTitle = pictureTitle;
this.pictureRoad = pictureRoad;
}
public PictureList() {
}
}