我正在使用配置了@EnableHypermediaSupport(type=HAL)的Spring Boot和Spring Hateoas。尽管在基本场景下工作正常,但我想能够向链接添加其他属性。例如,很容易返回将呈现诸如此类链接的链接:
{
"_links":{
"self":{
"href":"http://localhost/"
},
"something":[
{
"href":"http://some-url.com/something1"
},
{
"href":"http://some-url.com/something2"
}
]
}
我想要做的是向something rel中的对象添加更多属性。例如:
{
"_links":{
"self":{
"href":"http://localhost/"
},
"something":[
{
"name":"something1",
"href":"http://some-url.com/something1"
},
{
"name":"something2",
"href":"http://some-url.com/something2"
}
]
}
}
最好的方法是什么(最好使用ControllerLinkBuilder),而不需要创建自己的DTO?我尝试创建自己的Link子类并添加名称字段(以及getter和setter),但它们似乎被忽略了。
resource.addLink(new SuperLink(...))
代替resource.add(new Link(...))
。如果您需要更多信息,最好提出一个新的问题并描述您的情况。 - a better oliver