Spring HATEOAS - 两个相同的链接 [英] Spring HATEOAS - two same links
问题描述
最近我一直在用 Spring Data 做一些项目,用 HATEOAS 做一些项目.
lately I've been doing some projekt with Spring Data and Rest with HATEOAS.
我的问题是,在实体链接部分,我有 2 个相同的链接是否正常?
My question is, is it normal, that in entity links secion, I have 2 same links?
这里是存储库:
推荐答案
是的.但情况并非总是如此:用户"链接实际上是一个模板化链接,在某些情况下会得到丰富.
Yes it is. But it's not always the case: the 'user' link is actually a templated link that gets enriched in certain cases.
例如,您是否应该定义以下 投影:
For instance, should you define the following projection:
@Projection(name = "summary", types = { User.class })
interface Summary {
String getUsername();
String getEmail();
}
然后 user
链接将显示投影参数:
then the user
link would show the projection parameter:
...
"_links" : {
"self" : {
"href" : "http://localhost:8080/users/1"
},
"user" : {
"href" : "http://localhost:8080/users/1{?projection}"
"templated" : true
}
您可以通过 GETting http://localhost:8080/users/1?projection=summary
来获取用户 1 的摘要.
And you could be able to get a summary of user 1 by GETting http://localhost:8080/users/1?projection=summary
.
这篇关于Spring HATEOAS - 两个相同的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!