강의

멘토링

커뮤니티

Inflearn Community Q&A

zxcqew327554's profile image
zxcqew327554

asked

[Revised 2023-11-27] Developing RESTful Web Services using Spring Boot 3.x

HATEOAS 3단계 적용 질문입니다 !

Written on

·

370

0

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>

hateoas 3.2.png

섹션 4 Level3 단계의 REST API 구현을 위한 HATEOAS 적용에서 오류가 발생했습니다.
retrieveAllUsers

@GetMapping("/users")
public List<User> retrieveAllUsers() {
    return service.findAll();
}


전체 조회 메서드는 잘 작동이 되는데

retrieveUser

@GetMapping("/users/{id}")
public EntityModel<User> retrieveUser(@PathVariable int id) {

    User user = service.findOne(id);

    if (user == null){
        throw new UserNotFoundException(String.format("ID[%s] not found", id));
    }

    EntityModel<User> entityModel = EntityModel.of(user);
    
    WebMvcLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers());

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

    return entityModel;

}

검색.png

ㅠ.png
이런 오류가 발생했습니다.

어떻게 해결해야 할까요?

rest-apispring-boot

Answer 1

0

zxcqew327554님의 프로필 이미지
zxcqew327554
Questioner

WebMvcLinkBuilder linkTo = linkTo(UserController.class).slash("users");

우선 이렇게 바꾸니까 작동했습니다.

zxcqew327554's profile image
zxcqew327554

asked

Ask a question