Skip to content

Commit

Permalink
Demo app..
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvydas Jonusonis committed Mar 27, 2015
1 parent 1229518 commit 77512e9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
17 changes: 17 additions & 0 deletions initial/src/main/java/hello/Application.java
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);

}

}
22 changes: 22 additions & 0 deletions initial/src/main/java/hello/Greeting.java
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;
}
}
28 changes: 28 additions & 0 deletions initial/src/main/java/hello/GreetingController.java
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);
}

}

0 comments on commit 77512e9

Please sign in to comment.