Spring HATEOAS - two same links

橙三吉。 提交于 2020-01-24 20:41:11

问题


lately I've been doing some projekt with Spring Data and Rest with HATEOAS.

My question is, is it normal, that in entity links secion, I have 2 same links?

Here is repository:

Repository


回答1:


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();

}

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
  }

And you could be able to get a summary of user 1 by GETting http://localhost:8080/users/1?projection=summary.



来源:https://stackoverflow.com/questions/47649664/spring-hateoas-two-same-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!