1
Ich habe zwei Entitäten definiert:von Child-Objekt im Frühjahr freilegen Feld hateoas
@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;
//...
}
ich folgende JSON-Antwort auf den Aufruf zu/api/videoposts:
"_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"
}
}
} ]
Ich mag würde aussetzen der Uploader-Name innerhalb dieser Antwort direkt. I.e.
"uploader" : {
"userName": theName
"href" : "http://localhost:8080/api/videoPosts/1/uploader"
}
Wie konnte ich das erreichen?
zu verstecken Sind Sie Feder-data-Rest mit zur Verfügung zu stellen die HTTP-Endpunkte oder haben Sie Ihren eigenen Controller geschrieben und 'org.springframework.hateoas.Resource' verwendet, um die Ressourcen zu rendern? – systemfreund