2 回答

TA貢獻1793條經驗 獲得超6個贊
我簡單地添加了它@JsonIgnore并且它工作了。
@OneToMany(fetch = FetchType.LAZY, mappedBy = "department")
@JsonIgnore
private Set<Employee> employees;
還
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "DEPT_ID", nullable = false)
@JsonIgnore
private Department department;

TA貢獻1872條經驗 獲得超4個贊
如果您想在父實體的 JSON 響應中保留值,您可以執行以下操作:
//without @JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "DEPT_ID", nullable = false)
private Department department;
還
//with @JsonIgnore
@OneToMany(fetch = FetchType.LAZY, mappedBy = "department")
@JsonIgnore
private Set<Employee> employees;
以及沒有員工值的子實體中的 @Override hashCode() 方法,如下所示:
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((departmentId == null) ? 0 : departmentId .hashCode());
result = prime * result + ((departmentName == null) ? 0 : departmentName.hashCode());
result = prime * result + ((departmentCode == null) ? 0 : departmentCode.hashCode());
return result;
}
添加回答
舉報