Procházet zdrojové kódy

Rename implementation classes and update Jackson dependency to Jackson 2.

Craig Walls před 13 roky
rodič
revize
b229ca6a7e

+ 21
- 0
src/main/java/hello/Greeting.java Zobrazit soubor

@@ -0,0 +1,21 @@
1
+package hello;
2
+
3
+public class Greeting {
4
+
5
+	private final long id;
6
+	private final String content;
7
+
8
+	public Greeting(long id, String content) {
9
+		this.id = id;
10
+		this.content = content;
11
+	}
12
+
13
+	public long getId() {
14
+		return id;
15
+	}
16
+
17
+	public String getContent() {
18
+		return content;
19
+	}
20
+
21
+}

+ 23
- 0
src/main/java/hello/HelloWorldController.java Zobrazit soubor

@@ -0,0 +1,23 @@
1
+package hello;
2
+
3
+import java.util.concurrent.atomic.AtomicLong;
4
+
5
+import org.springframework.stereotype.Controller;
6
+import org.springframework.web.bind.annotation.RequestMapping;
7
+import org.springframework.web.bind.annotation.RequestMethod;
8
+import org.springframework.web.bind.annotation.RequestParam;
9
+import org.springframework.web.bind.annotation.ResponseBody;
10
+
11
+@Controller
12
+@RequestMapping("/hello-world")
13
+public class HelloWorldController {
14
+
15
+	private static final String template = "Hello, %s!";
16
+	private final AtomicLong counter = new AtomicLong();
17
+
18
+	@RequestMapping(method=RequestMethod.GET)
19
+	public @ResponseBody Greeting sayHello(@RequestParam(value="name", required=false, defaultValue="Stranger") String name) {
20
+		return new Greeting(counter.incrementAndGet(), String.format(template, name));
21
+	}
22
+	
23
+}