STS无法理解我的hateoas导入并报告错误

问题描述 投票:0回答:1

我正在按照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-boot spring-hateoas
1个回答
13
投票

导入已更新。

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
© www.soinside.com 2019 - 2024. All rights reserved.