Spring boot STS不能';无法理解我的hateoas导入和报告错误
根据春季的官方教程,我正在构建一个RESTful服务。我按照说明添加了依赖项,但是STS(Spring工具套件)无法理解我的函数 STS无法理解Spring boot STS不能';无法理解我的hateoas导入和报告错误,spring-boot,spring-hateoas,Spring Boot,Spring Hateoas,根据春季的官方教程,我正在构建一个RESTful服务。我按照说明添加了依赖项,但是STS(Spring工具套件)无法理解我的函数 STS无法理解methodOn()或lintTo()并不断给出错误,请帮我解决。 pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-hateoas</art
methodOn()
或lintTo()
并不断给出错误,请帮我解决。pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
org.springframework.boot
弹簧靴启动器hateoas
控制器:
@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"));
}
@GetMapping(“/employees/{id}”)
资源一(@PathVariable Long id){
Employee=repository.findById(id)
.orelsetrow(()->new EmployeeNotFoundException(id));
返回新资源(员工、,
链接到(methodOn(EmployeeController.class).one(id)).withSelfRel(),
链接到(methodOn(EmployeeController.class).all()).withRel(“雇员”);
}
我在github上搜索了源代码,估计需要从库中进行静态导入
我添加了这一行,现在问题已经解决了:
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
导入已更新
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
它给出了哪些错误?类型EmployeeController和linkTo()的方法methodOn(类)未定义,根据您的详细信息,我看不到错误。什么是错误?methodOn()是哪个类的一部分?该类的对象在哪里?methodOn()和linkTo()都应该包含在hateoas中,我已经添加了依赖项,但仍然错误我猜导入是静态的,所以STS无法找到我想要的。我猜这个框架没有那么周到