spring-boot - STS 无法理解我的 hatoas 导入并报告错误
问题描述
我正在根据 Spring 的官方教程构建一个 RESTful 服务。我按照说明添加了依赖项,但 STS(Spring Tool Suite)无法弄清楚我的功能。
STS无法理解methodOn()
或lintTo()
不断出错,请帮助我。
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
控制器:
@GetMapping("/employees/{id}")
Resource<Employee> one(@PathVariable Long id) {
Employee employee = repository.findById(id)
.orElseThrow(() -> new EmployeeNotFoundException(id));
return new Resource<>(employee,
linkTo(methodOn(EmployeeController.class).one(id)).withSelfRel(),
linkTo(methodOn(EmployeeController.class).all()).withRel("employees"));
}
解决方案
导入已更新。
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
推荐阅读
- javascript - 将表格元素居中对齐
- javascript - 'TypeError:使用'react-router-dom'的'useHistory'钩子时无法读取未定义的属性(读取'push')'
- javascript - 如何在切换按钮中创建亮/暗功能
- reactjs - 如何删除 TextInput 中的下划线(Expo - react native)?
- swift - 在同一工作区的另一个项目中使用一个类
- angular - 使用 AngularJS 在 pouch DB 中保存、检索和显示图像作为附件
- python - 如何预测标题的唯一性?
- unreal-engine4 - 在虚幻引擎中管理 AI 重用的最有效方法是什么?
- python - Google Colab 中的 Glob 函数没有提供任何输出
- python-3.x - 获取 psycopg.ProgrammingError:传递数据库参数时无效的连接选项“数据库”