您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Jackson双向关系(一对多)不起作用

Jackson双向关系(一对多)不起作用

由于您在实体中使用@JsonBackReferenceonCustomer属性,因此LoanCustomer对象将不包含在序列化中。使用@JsonManagedReferenceCustomerLoan对象和使用@JsonBackReferenceLoan的物业Customer实体。

这将序列化Customer您的Loan实体的属性。但是Customer对象序列化将不包含该Loan属性。您需要选择关系的一侧进行序列化。

要允许双方,请@JsonIdentityInfo在您的实体中使用注释,然后删除@JsonBackReference@JsonManagedReference。您的实体将类似于:

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "customerId")
public class Customer implements Serializable {
    ...
}

property@JsonIdentityInfo参考您的实体ID属性Customer这将是customerId。为此LoanItem也。

其他 2022/1/1 18:18:03 有633人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶