[英]Hateoas - No suitable constructor found for Link(java.lang.String)
For a REST API, in the controller I'm applying hateoas.对于 REST API,在 controller 中我应用了 hateoas。 When adding the part of Link in the methods, I get the follow error:
Cannot resolve constructor 'Link(String)'
在方法中添加链接部分时,出现以下错误:
Cannot resolve constructor 'Link(String)'
In the pom.xml:在 pom.xml 中:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
The code is as follows:代码如下:
@GetMapping
public @ResponseBody ResponseEntity<List<UserResponseDTO>> get() {
// Retrieve users
List<UserResponseDTO> responseDTOS = new ArrayList<>();
List<User> users = userService.getUsers();
// Convert to responseDTOS
for (User user : users) {
UserResponseDTO userResponseDTO = new UserResponseDTO(user.getId(), user.getFirstName(), user.getLastName());
Link get = new Link("http://localhost:8081/user/").withRel("GET");
userResponseDTO.add(get);
responseDTOS.add(userResponseDTO);
}
return new ResponseEntity<>(responseDTOS, HttpStatus.OK);
}
Does anyone know how to solve this?有谁知道如何解决这个问题?
Link(String)
is deprecated and may be removed in some new version. Link(String)
已弃用,可能会在某些新版本中删除。 Also Link(String)
uses the protected access modifier meaning you should access it only from the same package.此外,
Link(String)
使用受保护的访问修饰符,这意味着您只能从同一个 package 访问它。
You can still create the Link
using the of
static method which by the way is defined with public access modifier.您仍然可以使用 static 方法创建
Link
of
该方法是使用公共访问修饰符定义的。
So it should be所以应该是
Link get = Link.of("http://localhost:8081/user/").withRel("GET");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.