在 Spring Java 中,尤其是在 JoinColumn 中,如果我们执行 JoinColumn,例如 JoinColumn(name="guest_id")。然后将显示所有客人数据。而我只想检索一个数据,这只是名称。
@Column(name = "guest_id")
private Integer guestId;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "guest_id", insertable = false, updatable = false)
private String guestName;
当邮递员发出请求时,结果将是这样的
"guestCard": {
"id": 53,
"idPic": null,
"guestType": null,
"title": "mr",
"name": "RIKO JANUAR",
"phoneNumber": "08100000",
"email": "riko@email.com",
"gender": "male",
"bDay": "2019-10-29",
"nationality": "AF",
"idCard": "21321131231",
"validity": "2019-10-29",
"telpFax": null,
"address": "bandung",
"job": "Musician"
}
我想要的是只取并显示一个,即名称。像这样
"guestCard": {
"name": "RIKO JANUAR"
}
我用这种方式尝试过,但没有用
@Column(name = "guest_id")
private Integer guestId;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "name.guest_id", insertable = false, updatable = false) //this is not work
private String guestName;