首页 > 解决方案 > 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"));
}

标签: spring-bootspring-hateoas

解决方案


导入已更新。

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

推荐阅读