{
"_embedded" : {
"patient" : {
"firstName" : "Kidus",
"_links" : {
"self" : {
"href" : "http://localhost:8090/api/patients/2{?projection}",
"templated" : true
},
}
}
如你所见,我有一个嵌入式实体(病人)。它返回所有数据,包括实体的链接,但链接是模板化的。我没有使用前端的HATEOAS客户端,我也不打算改变这个方向。所以我需要一个正常的非模板化的链接。有没有什么非黑客的方法来实现这个目标?
你可以用这种方式强制展开模板。
@GetMapping("/myresources/{id}")
public EntityModel<MyResource> myResource(String id) {
MyResource resource = ...;
return new EntityModel<>(
resource,
linkTo(methodOn(getClass()).myResource(id)).withSelfRel().expand(id));
}