【发布时间】:2020-07-27 15:54:15
【问题描述】:
我最近将我们的应用程序升级到使用 Spring Hateoas 1.1.0.RELEASE 的 Spring Boot 2.3.2.RELEASE。
我的任何链接的基本 rel 路径是:“urn:eim:linkrel:”
使用 Spring Boot 2.2.6.RELEASE,响应如下:
{
"_links": {
"urn:eim:linkrel:users": {
"href": "https://localhost:8080/v1/users"
}
}
}
使用 Spring Boot 2.3.2.RELEASE,响应更改如下:
{
"_links": {
"urn:eim": {
"href": "https://localhost:8080/v1/users"
}
}
}
我生成上述响应的代码:
import javax.servlet.http.HttpServletRequest;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DemoController {
@RequestMapping(value = "/service", method = RequestMethod.GET, produces = "application/hal+json")
public HttpEntity<RepresentationModel<?>> service(HttpServletRequest request) {
RepresentationModel<?> service = new RepresentationModel<>();
service.add(Link.of("https://localhost:8080/v1/users", "urn:eim:linkrel:users"));
return new ResponseEntity<>(service, HttpStatus.OK);
}
}
有人有类似的问题吗?谁能告诉我解决此问题的解决方案。
【问题讨论】:
标签: spring spring-boot spring-mvc spring-hateoas