#13 aleenarm

Otwarty
aleenarm chce scalić 1 commity/ów z aleenarm/ZCW-SpringZero:master do master

+ 13
- 0
initial/src/main/java/hello/Application.java Wyświetl plik

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

+ 20
- 0
initial/src/main/java/hello/Greeting.java Wyświetl plik

@@ -0,0 +1,20 @@
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
+}

+ 19
- 0
initial/src/main/java/hello/GreetingController.java Wyświetl plik

@@ -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
+
8
+@RestController
9
+public class GreetingController {
10
+
11
+    private static final String template = "Hello, %s!";
12
+    private final AtomicLong counter = new AtomicLong();
13
+
14
+    @RequestMapping("/greeting")//BY Default get
15
+    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
16
+        return new Greeting(counter.incrementAndGet(),// returns a new Greeting object with id and content attributes based on the next value from the counter
17
+                String.format(template, name));//and formats the given name by using the greeting template
18
+    }
19
+}