STS无法理解我的仇恨导入和报告错误

时间:2018-12-20 13:09:56

标签: spring-boot spring-hateoas

根据Spring的官方教程,我正在构建RESTful服务。我按照说明添加了依赖项,但是STS(Spring工具套件)无法弄清楚我的功能。

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"));
}

2 个答案:

答案 0 :(得分:2)

导入已更新。

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;

答案 1 :(得分:-1)

我在github上搜索了源代码,猜测那里需要从库中进行静态导入。

我添加了这一行,现在问题已解决:

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;