Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
cd13a168
Commit
cd13a168
authored
Feb 28, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Align HATEAOS sample with latest breaking API changes
See gh-15939
parent
66f00c20
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
10 deletions
+11
-10
CustomerController.java
.../src/main/java/sample/hateoas/web/CustomerController.java
+11
-10
No files found.
spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/web/CustomerController.java
View file @
cd13a168
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -19,10 +19,10 @@ package sample.hateoas.web;
...
@@ -19,10 +19,10 @@ package sample.hateoas.web;
import
sample.hateoas.domain.Customer
;
import
sample.hateoas.domain.Customer
;
import
sample.hateoas.domain.CustomerRepository
;
import
sample.hateoas.domain.CustomerRepository
;
import
org.springframework.hateoas.
EntityLinks
;
import
org.springframework.hateoas.
CollectionModel
;
import
org.springframework.hateoas.E
xposesResourceFor
;
import
org.springframework.hateoas.E
ntityModel
;
import
org.springframework.hateoas.
Resource
;
import
org.springframework.hateoas.
server.EntityLinks
;
import
org.springframework.hateoas.
Resources
;
import
org.springframework.hateoas.
server.ExposesResourceFor
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
...
@@ -47,16 +47,17 @@ public class CustomerController {
...
@@ -47,16 +47,17 @@ public class CustomerController {
}
}
@GetMapping
(
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@GetMapping
(
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
HttpEntity
<
Resources
<
Customer
>>
showCustomers
()
{
HttpEntity
<
CollectionModel
<
Customer
>>
showCustomers
()
{
Resources
<
Customer
>
resources
=
new
Resources
<>(
this
.
repository
.
findAll
());
CollectionModel
<
Customer
>
resources
=
new
CollectionModel
<>(
this
.
repository
.
findAll
());
resources
.
add
(
this
.
entityLinks
.
linkToCollectionResource
(
Customer
.
class
));
resources
.
add
(
this
.
entityLinks
.
linkToCollectionResource
(
Customer
.
class
));
return
new
ResponseEntity
<>(
resources
,
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
resources
,
HttpStatus
.
OK
);
}
}
@GetMapping
(
path
=
"/{id}"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@GetMapping
(
path
=
"/{id}"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
HttpEntity
<
Resource
<
Customer
>>
showCustomer
(
@PathVariable
Long
id
)
{
HttpEntity
<
EntityModel
<
Customer
>>
showCustomer
(
@PathVariable
Long
id
)
{
Resource
<
Customer
>
resource
=
new
Resource
<>(
this
.
repository
.
findOne
(
id
));
EntityModel
<
Customer
>
resource
=
new
EntityModel
<>(
this
.
repository
.
findOne
(
id
));
resource
.
add
(
this
.
entityLinks
.
linkTo
Single
Resource
(
Customer
.
class
,
id
));
resource
.
add
(
this
.
entityLinks
.
linkTo
Item
Resource
(
Customer
.
class
,
id
));
return
new
ResponseEntity
<>(
resource
,
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
resource
,
HttpStatus
.
OK
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment