|
@@ -0,0 +1,19 @@
|
|
1
|
+package hello;
|
|
2
|
+
|
|
3
|
+import java.util.concurrent.atomic.AtomicLong;
|
|
4
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
5
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
6
|
+import org.springframework.web.bind.annotation.RestController;
|
|
7
|
+@RestController
|
|
8
|
+class GreetingController {
|
|
9
|
+ private static final String template = "Hello, %s!";
|
|
10
|
+ private final AtomicLong counter = new AtomicLong();
|
|
11
|
+ @RequestMapping("/greeting")//BY Default get
|
|
12
|
+ public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
|
|
13
|
+ return new Greeting(counter.incrementAndGet(), String.format(template, name));
|
|
14
|
+
|
|
15
|
+ // returns a new Greeting object with id and content attributes based on the next value from the counter
|
|
16
|
+ //String.format(template, name);//and formats the given name by using the greeting template
|
|
17
|
+ }
|
|
18
|
+}
|
|
19
|
+
|