forked from spring-guides/gs-rest-hateoas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arvydas Jonusonis
committed
Mar 27, 2015
1 parent
1229518
commit 77512e9
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package hello; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* Created by Arvydas on 3/16/15. | ||
*/ | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package hello; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.springframework.hateoas.ResourceSupport; | ||
|
||
/** | ||
* Created by Arvydas on 3/16/15. | ||
*/ | ||
public class Greeting extends ResourceSupport { | ||
|
||
private final String content; | ||
|
||
@JsonCreator | ||
public Greeting(@JsonProperty("content") String content) { | ||
this.content = content; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package hello; | ||
|
||
import org.springframework.hateoas.mvc.ControllerLinkBuilder; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
/** | ||
* Created by Arvydas on 3/16/15. | ||
*/ | ||
@Controller | ||
public class GreetingController { | ||
|
||
public static final String TEMPLATE = "Hello, %s"; | ||
|
||
@RequestMapping("/greeting") | ||
public HttpEntity<Greeting> greeting( | ||
@RequestParam(value="name", required = false, defaultValue = "World") String name | ||
){ | ||
Greeting greeting = new Greeting(String.format(TEMPLATE, name)); | ||
greeting.add(ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(GreetingController.class).greeting(name)).withSelfRel()); | ||
return new ResponseEntity<Greeting>(greeting, HttpStatus.OK); | ||
} | ||
|
||
} |