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条经验 获得超3个赞
如果您想在父实体的 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;
}
添加回答
举报