我有 2个具有一对多关系的实体CallRecords和CallRecordOperators ,如下所示
public class CallRecords {
@Id
@Column(name = "id", unique = true)
private String id;
@Column(columnDefinition = "varchar(255) default ''")
private String callerNumber = "";
@OneToMany(mappedBy="callrecord")
private List<CallRecordOperators> callRecordOperators = new ArrayList<CallRecordOperators>();
//getter setters
}
public class CallRecordOperators {
@Id
@Column(name = "id", length = 50, unique = true, nullable = false, insertable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@JsonIgnore
@ManyToOne
@JoinColumn(name = "callRecordId")
private CallRecords callrecord;
@ManyToOne
@JoinColumn(name = "operatorId")
private Operator operator;
@Formats.DateTime(pattern = "yyyy-MM-dd HH:mm:yy")
@Column(columnDefinition = "TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP")
private Date startTime = new Date();
@Column(columnDefinition = "varchar(100) default ''")
private String dialStatus;
//getter setter
}
因此,如果用户要求所有“CallRecords”数据,我还必须提供“CallRecordOperators”,因为它们是相关的。
Mapper 和 DTO 的当前代码
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CallRecordsMapper {
CallRecordsMapper INSTANCE = Mappers.getMapper(CallRecordsMapper.class);
@Mapping(source="callRecordOperators",target = "operators")
CallRecordsDto callRecordsToCallRecordsDto(CallRecords callRecords);
public abstract CallRecordOperatorsDto toTarget(CallRecordOperators source);
List<CallRecordsDto> callRecordsToCallRecordsDtos(List<CallRecords> callRecords);
}
public class CallRecordsDto {
private String callerNumber;
private List<CallRecordOperatorsDto> operators;
//getter setters
}
public class CallRecordOperatorsDto {
private String callRecordsId;
private String operatorId;
private String operatorName;
private String currentTime;
// getter setter
}
但是对于上面的代码,我得到了
{
"callerNumber": "9898989898",
"operators": [{
"callRecordsId": null,
"operatorId": null,
"operatorName": null,
"currentTime": null
}, {
"callRecordsId": null,
"operatorId": null,
"operatorName": null,
"currentTime": null
}]
}
运算符数组的值为空。他可能是什么问题?