我用spring实现了一个后端,它通过restapi将功能和数据导出到用angular开发的前端。上下文涉及提供一个服务,其中同一个用户可以签订多个合同。在这种情况下,可以将现有合同与另一个注册用户相关联。因此,我实现了以下类,它们各自的控制器和存储库
@Entity
@JsonIdentityInfo( generator = ObjectIdGenerators.PropertyGenerator.class, property = "codFiscale")
public class Utente {
@Id
private String codFiscale;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "titolare")
private List<ContrattoFornitura> contratti;
//other fields + set and get methods
----
@Entity
@JsonIdentityInfo( generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class ContrattoFornitura {
@Id @GeneratedValue
private long id;
@ManyToOne @JoinColumn(name="titolare")
@JsonProperty("titolare")
private Utente titolare;
//other fields + set and get methods
我意识到,通过检索当前存在的所有契约,外部引用的所有公开字段只返回用户指定的第一个契约,而对于后续契约,只返回标识符。通过调试,我注意到jpa存储库的find方法正确地返回了外部实体1的所有公开字段,但是只使用键构建响应,正如您从wireshark2的嗅探数据包中看到的那样。是否有一种方法可以在所有情况下返回被引用实体的所有字段,或者我必须在前端以某种方式检索信息?
暂无答案!
目前还没有任何答案,快来回答吧!