Spring MVC / Spring 数据数据获取递归
Spring MVC / Spring Data data fetch recursion
我有一个 one-to-many relationship
的实体(例如 Person o->m Book
)。如果我想在控制器中获取一个有书的人,它会导致递归。 @JsonIgnore
by FasterXML
有帮助,但是如果我想要 bidirectional
不递归地获取怎么办。例如 fetch Person with Books
和 fetch Book with Persons
?
使用@JsonBackReference
class Person{
@OneToMany(mappedBy="person",fetch = FetchType.EAGER)
private List<Book> books;
...
}
class Book {
@ManyToOne
@JoinColumn(columnDefinition="integer", name = "person", nullable=false)
@JsonBackReference
private Person person;
...
}
我有一个 one-to-many relationship
的实体(例如 Person o->m Book
)。如果我想在控制器中获取一个有书的人,它会导致递归。 @JsonIgnore
by FasterXML
有帮助,但是如果我想要 bidirectional
不递归地获取怎么办。例如 fetch Person with Books
和 fetch Book with Persons
?
使用@JsonBackReference
class Person{
@OneToMany(mappedBy="person",fetch = FetchType.EAGER)
private List<Book> books;
...
}
class Book {
@ManyToOne
@JoinColumn(columnDefinition="integer", name = "person", nullable=false)
@JsonBackReference
private Person person;
...
}