我有 2 个引用的实体 Author 和 Book,并且在它之间有引用 Many2one=>one2many,我在实现方面有问题吗?当进入时,/authors我得到了所有作者的书,但每本书中都有他的作者(以及所有自己的书),反之亦然
一点问题,我需要得到 /authors- 所有没有他的书的作者
/author/{id}和他的所有书(里面的书不需要作者) /books所有书里有作者的书(但里面的书不需要作者) /book/{id}有作者的书(里面没有他的书)
@Entity(name = "Author")
@Table(name = "authors")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Author {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "title")
private String title;
@Column(name = "description")
private String description;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "author", cascade = CascadeType.ALL)
private List<Book> books; ....
和
@Entity
@Table(name = "books")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Book{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "price")
private double price;
@Column(name = "title")
private String title;
@Column(name = "description")
private String description;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "author_id")
private Author author; ....
守着一只汪
相关分类