From cd13a1685c383ccc78738c8a70ebf4344a1d15e2 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 28 Feb 2019 19:37:00 +0000 Subject: [PATCH] Align HATEAOS sample with latest breaking API changes See gh-15939 --- .../hateoas/web/CustomerController.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/web/CustomerController.java b/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/web/CustomerController.java index 1412771860..097d7724a5 100644 --- a/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/web/CustomerController.java +++ b/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/web/CustomerController.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,10 @@ package sample.hateoas.web; import sample.hateoas.domain.Customer; import sample.hateoas.domain.CustomerRepository; -import org.springframework.hateoas.EntityLinks; -import org.springframework.hateoas.ExposesResourceFor; -import org.springframework.hateoas.Resource; -import org.springframework.hateoas.Resources; +import org.springframework.hateoas.CollectionModel; +import org.springframework.hateoas.EntityModel; +import org.springframework.hateoas.server.EntityLinks; +import org.springframework.hateoas.server.ExposesResourceFor; import org.springframework.http.HttpEntity; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -47,16 +47,17 @@ public class CustomerController { } @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) - HttpEntity> showCustomers() { - Resources resources = new Resources<>(this.repository.findAll()); + HttpEntity> showCustomers() { + CollectionModel resources = new CollectionModel<>( + this.repository.findAll()); resources.add(this.entityLinks.linkToCollectionResource(Customer.class)); return new ResponseEntity<>(resources, HttpStatus.OK); } @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - HttpEntity> showCustomer(@PathVariable Long id) { - Resource resource = new Resource<>(this.repository.findOne(id)); - resource.add(this.entityLinks.linkToSingleResource(Customer.class, id)); + HttpEntity> showCustomer(@PathVariable Long id) { + EntityModel resource = new EntityModel<>(this.repository.findOne(id)); + resource.add(this.entityLinks.linkToItemResource(Customer.class, id)); return new ResponseEntity<>(resource, HttpStatus.OK); }