Hateoas-找不到适合链接的构造函数(java.lang.string)
对于REST API,在控制器中,我正在应用Hateoas。在方法中添加链接的一部分时,我会收到以下错误: 无法
在pom.xml中解析构造函数'link(string)':
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
代码如下:
@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);
}
有人知道如何解决这个问题吗?
For a REST API, in the controller I'm applying hateoas. When adding the part of Link in the methods, I get the follow error:Cannot resolve constructor 'Link(String)'
In the 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
链接(字符串)
被弃用,可以在某些新版本中删除。另外,链接(字符串)
使用受保护的访问修饰符,这意味着您应仅从同一软件包访问它。您仍然可以使用的
静态方法创建
static方法。链接
,该方法通过公共访问修改器定义了所以应该是
Link(String)
is deprecated and may be removed in some new version. AlsoLink(String)
uses the protected access modifier meaning you should access it only from the same package.You can still create the
Link
using theof
static method which by the way is defined with public access modifier.So it should be