美文网首页
OneToMany一对多

OneToMany一对多

作者: 啦啦啦哈啦啦啦 | 来源:发表于2018-10-12 15:30 被阅读0次

情景:以极简图床为例,图床内有很多相册,每一个相册里对应着一些图片,此时相册为一,图片为多。

代码

  • Album.java(相册类)
import lombok.Data;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.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() {
    }

    public Album(String albumCover, String albumTitle, String albumDescription, Integer likes) {
        this.albumCover = albumCover;
        this.albumTitle = albumTitle;
        this.albumDescription = albumDescription;
        this.likes = likes;
    }
}
  • PictureList.java(相片类)

import io.swagger.models.auth.In;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
@Data
public class PictureList {
    @GeneratedValue
    @Id
    private Integer id;
    private String pictureTitle;
    private String pictureLink;

    public PictureList(String pictureTitle, String pictureLink) {
        this.pictureTitle = pictureTitle;
        this.pictureRoad = pictureLink;
    }

    public PictureList() {
    }

}

相关文章

  • OneToMany一对多

    情景:以极简图床为例,图床内有很多相册,每一个相册里对应着一些图片,此时相册为一,图片为多。 代码 Album.j...

  • OneToMany一对多

    情景:以极简图床为例,图床内有很多相册,每一个相册里对应着一些图片,此时相册为一,图片为多。 代码 Album.j...

  • hibernate笔记

    一对多 注解:@OneToMany(cascade = CascadeType.ALL, orphanRemova...

  • DBFlow:关系注解

    表 定义如下两张表:工厂下面有一对设备: Factory: Device: OneToMany 工厂中对于一对多这...

  • SpringBoot一对多

    Album类(一)对PictureList类(多) Album类: 1、@OneToMany和@JoinColum...

  • cannot simultaneously fetch mult

    问题概述 @oneToMany与@ManyToOne 关联 "一" 方注解如下: @OneToMany(mappe...

  • failed to lazily initialize a co

    问题概述 @oneToMany与@ManyToOne关联 "一" 方注解如下: @OneToMany(mapped...

  • springboot(一对多)

    两个实体类,Album类(一)对PictureList类(多) 下面是Album类 1、@OneToMany和@J...

  • SpringBoot实现一对多

    两个实体类,Album类(一)对PictureList类(多) 下面是Album类1、@OneToMany和@Jo...

  • Use of @OneToMany or @ManyToMany

    Use of @OneToMany or @ManyToMany targeting an unmapped cl...

网友评论

      本文标题:OneToMany一对多

      本文链接:https://www.haomeiwen.com/subject/tcrgaftx.html