diff --git a/initial/src/main/java/hello/Application.java b/initial/src/main/java/hello/Application.java new file mode 100644 index 0000000..8441f92 --- /dev/null +++ b/initial/src/main/java/hello/Application.java @@ -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); + + } + +} diff --git a/initial/src/main/java/hello/Greeting.java b/initial/src/main/java/hello/Greeting.java new file mode 100644 index 0000000..ca78002 --- /dev/null +++ b/initial/src/main/java/hello/Greeting.java @@ -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; + } +} diff --git a/initial/src/main/java/hello/GreetingController.java b/initial/src/main/java/hello/GreetingController.java new file mode 100644 index 0000000..6ab2472 --- /dev/null +++ b/initial/src/main/java/hello/GreetingController.java @@ -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( + @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, HttpStatus.OK); + } + +}