gpt4 book ai didi

spring-boot - 找不到资源和ControllerLinkBuilder并已弃用

转载 作者:行者123 更新时间:2023-12-04 17:14:32 26 4
gpt4 key购买 nike

我正在使用带有HATEOAS和Gradle的Spring Boot 2.2.0.M1。

implementation 'org.springframework.boot:spring-boot-starter-hateoas'

现在,IDE(IntelliJ IDEA 2018.3)找不到 Resource,并且 ControllerLinkBuilder标记为 不推荐使用
package com.example.restfulwebservicegradle.user;

import static org.springframework.hateoas.server.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

import com.example.restfulwebservicegradle.User;
import com.example.restfulwebservicegradle.UserDaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.server.mvc.ControllerLinkBuilder;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import javax.validation.Valid;
import java.net.URI;
import java.util.List;

@RestController
public class UserResource {

@Autowired
private UserDaoService service;

@GetMapping("users/{id}")
public Resource<User> retrieveUser(@PathVariable int id) {
User user = service.findOne(id);

if (user == null)
throw new UserNotFoundException("id-" + id);


// Resource not found
Resource<User> resource = new Resource<User>(user);

// Deprecated
ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers());

resource.add(linkTo.withRel("all-users"));

return resource;
}
}

根据IDE可用的导入为:
enter image description here

我该如何解决?

我的目标是从HATEOAS中找到 Resource并使用 ControllerLinkBuilder的替代品。

最佳答案

最根本的变化是Spring HATEOAS不会创建资源。这就是Spring MVC/Spring WebFlux的功能。我们创建超媒体的供应商中立表示。因此,我们重命名了这些核心类型:

LINK- https://spring.io/blog/2019/03/05/spring-hateoas-1-0-m1-released#overhaul

  • ResourceSupport现在是RepresentationModel
  • 资源现在是EntityModel
  • 资源现在是CollectionModel
  • PagedResources现在是PagedModel
  • 关于spring-boot - 找不到资源和ControllerLinkBuilder并已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55770163/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com