Align HATEAOS sample with latest breaking API changes
See gh-15939
This commit is contained in:
parent
66f00c20ad
commit
cd13a1685c
|
@ -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<Resources<Customer>> showCustomers() {
|
||||
Resources<Customer> resources = new Resources<>(this.repository.findAll());
|
||||
HttpEntity<CollectionModel<Customer>> showCustomers() {
|
||||
CollectionModel<Customer> 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<Resource<Customer>> showCustomer(@PathVariable Long id) {
|
||||
Resource<Customer> resource = new Resource<>(this.repository.findOne(id));
|
||||
resource.add(this.entityLinks.linkToSingleResource(Customer.class, id));
|
||||
HttpEntity<EntityModel<Customer>> showCustomer(@PathVariable Long id) {
|
||||
EntityModel<Customer> resource = new EntityModel<>(this.repository.findOne(id));
|
||||
resource.add(this.entityLinks.linkToItemResource(Customer.class, id));
|
||||
return new ResponseEntity<>(resource, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue