h3yon / Spring-In-Action

0 stars 0 forks source link

Chapter6 hateos 변경 사항1 #1

Open h3yon opened 2 years ago

h3yon commented 2 years ago

문제 상황

Springboot 2.5.5 기준 hateos 변경사항

    @GetMapping("/recent")
    public Resources<Resource<Taco>> recentTacos(){
        PageRequest page = PageRequest.of(0, 12, Sort.by("createdAt").descending());
        List<Taco> tacos = tacoRepo.findAll(page).getContent();
        Resources<Resource<Taco>> recentResources = Resources.wrap(tacos);

        recentResources.add(new Link("http://localhost:8080/design/recent", "recents"));
        return recentResources;
    }

Resource, Resources 관련 에러

출력 에러

Cannot resolve symbol '*'

h3yon commented 2 years ago

아래와 같이 변경 후 해결

    @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;
    }