示例:如何根据A上的不同Gets返回/不返回B列表。
@Entity
public class A {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(mappedBy = "a", fetch = FetchType.LAZY)
private List<B> listBs ;
}
@Entity
public class B {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToOne(fetch = FetchType.LAZY)
private A a ;
}
答案 0 :(得分:0)
您可以使用@JsonManagedReference
,@JsonBackReference
@Entity
public class A {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(mappedBy = "a", fetch = FetchType.LAZY)
@JsonBackReference
private List<B> listBs ;
}
@Entity
public class B {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToOne(fetch = FetchType.LAZY)
@JsonManagedReference
private A a ;
}