1
class A{
private int id;
@oneToMany(mappedBy = "a")
private List<B> bList;
}
class B{
private int id;
@ManToOne
private A a;
}
存储库:
interfase BRepository{
@Query("select b from B b where b.a.id = ?1")
public List<B> getB(String id);
}
控制器:
private BRepository b;
@RequestMapping("/b")
public Object getB(){
return b.getB(1);
}
返回JSON中无限循环。
使用@JsonBackReference注解放在A级,正常结果:
class A{
private int id;
@oneToMany(mappedBy = "a")
@JsonBackReference //this property is ignored
private List<B> bList;
}
但是,当你查询类,返回的结果不bList(使用@JsonBackference),我能做些什么来回报bList属性?