Vincent Sima 6 years ago
parent
commit
ce23b4bd09

+ 12
- 0
initial/src/main/java/hello/Application.java View File

@@ -0,0 +1,12 @@
1
+package hello;
2
+
3
+
4
+import org.springframework.boot.SpringApplication;
5
+import org.springframework.boot.autoconfigure.SpringBootApplication;
6
+
7
+@SpringBootApplication
8
+public class Application {
9
+    public static void main(String[] args) {
10
+        SpringApplication.run(Application.class, args);
11
+    }
12
+}

+ 23
- 0
initial/src/main/java/hello/Greeting.java View File

@@ -0,0 +1,23 @@
1
+package main.java.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
+
22
+
23
+}

+ 21
- 0
initial/src/main/java/hello/GreetingController.java View File

@@ -0,0 +1,21 @@
1
+package hello;
2
+
3
+import org.springframework.web.bind.annotation.RequestMapping;
4
+import org.springframework.web.bind.annotation.RequestParam;
5
+import org.springframework.web.bind.annotation.RestController;
6
+
7
+import java.util.concurrent.atomic.AtomicLong;
8
+
9
+@RestController
10
+public class GreetingController {
11
+
12
+    private final AtomicLong counter = new AtomicLong();
13
+    private static final String template = "Hello, %s!";
14
+    @RequestMapping("/greeting")
15
+    public main.java.hello.Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
16
+
17
+        return new main.java.hello.Greeting(counter.incrementAndGet(),
18
+                String.format(template, name));
19
+
20
+    }
21
+}