我定义了两个实体:
@Entity
public class VideoPost {
private @Id
@GeneratedValue(strategy= GenerationType.IDENTITY) Long id;
private String videoTitle;
private @ManyToOne @JoinColumn(name = "VideoPost_Id") User uploader;
private boolean isPublished = false;
//....
}
@Entity
public class User {
private @Id @GeneratedValue(strategy=GenerationType.IDENTITY) Long id;
private String userName;
private Date registrationDate;
@OneToMany(mappedBy = "uploader", cascade = CascadeType.ALL) private List<VideoPost> videoPosts;
//...
}
我对/ api / videoposts的调用有以下JSON响应:
"_embedded" : {
"videoPosts" : [ {
"videoTitle" : "test video 1",
"uploadDate" : "2017-06-03T11:44:02.012+0000",
"_links" : {
"self" : {
"href" : "http://localhost:8080/api/videoPosts/1"
},
"videoPost" : {
"href" : "http://localhost:8080/api/videoPosts/1"
},
"uploader" : {
"href" : "http://localhost:8080/api/videoPosts/1/uploader"
}
}
} ]
我想直接在此响应中公开上传者名称。即。
"uploader" : {
"userName": theName
"href" : "http://localhost:8080/api/videoPosts/1/uploader"
}
我怎么能实现这个目标?