Skip to content

6장 REST서비스 생성하기에서의 hateoas 변경사항 #4

Description

@saechimdaeki

스프링 hateoas를 책과 다른 변경사항

  • ResourceSupport changed to RepresentationModel
  • Resource changed to EntityModel
  • Resources changed to CollectionModel
  • PagedResources changed to PagedModel
  • ResourceAssembler changed to RepresentationModelAssembler
  • ControllerLinkBuilder changed to WebMvcLinkBuilder
  • ResourceProcessor changed to RepresentationModelProcessor
    springframework에서의 hateoas가 위와 같이 변경되었습니다. 이를 고려해서 책을 보시면 됩니다!
    예를 들어 책 213쪽의 리스트 6.4 리소스에 하이퍼링크 추가하기를 이런식으로 변경하면 됩니다
        @GetMapping("/recent")
	public CollectionModel<EntityModel<Taco>> recentTacos(){
		PageRequest page=PageRequest.of(0, 12,Sort.by("createdAt").descending());
		
		List<Taco> tacos=tacoRepo.findAll(page).getContent();
		CollectionModel<EntityModel<Taco>> recentResources=CollectionModel.wrap(tacos);
		
		recentResources.add(new Link("http://localhost:8080/design/recent","recents"));
		return recentResources;
	}

p.s. spring 최신버젼으로 직접 코딩하시는분만...

Activity

  1. saechimdaeki commented on Feb 14, 2021

    @saechimdaeki
    Author

    최신버전의 스프링부트 hateoas 및 서브모듈을 너무 세세하게 나누는건 좀 꺼려서 두개로만 나눠봤는데 혹여나 나중에 보고 도움이 되셨으면 해서 제가 작성한 레포지토리의 CHAPTER6내용을 공유합니다

    https://github.com/saechimdaeki/SpringInAction5/tree/main/chap06

  2. saechimdaeki commented on Feb 15, 2021

    @saechimdaeki
    Author

    만약에 최신버전의 스프링 부트를 사용하면서 멀티모듈또한 책과 같이하고싶다면 챕터 6의 코드는 아니지만 챕터7부터
    https://github.com/saechimdaeki/SpringInAction5/tree/main/chap07 이런식으로 진행하면됩니다!!

    현재 기준스프링부트의 버젼 2.4.2입니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions