#18 KennethT867 SpringZero

Open
KennethT867 wants to merge 1 commits from KennethT867/ZCW-SpringZero:master into master

+ 4
- 0
complete/src/main/java/hello/HelloController.java View File

@@ -0,0 +1,4 @@
1
+package hello;
2
+
3
+public class HelloController {
4
+}

BIN
initial/.DS_Store View File


BIN
initial/src/.DS_Store View File


BIN
initial/src/main/.DS_Store View File


BIN
initial/src/main/java/.DS_Store View File


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

@@ -0,0 +1,33 @@
1
+package hello;
2
+
3
+import java.util.Arrays;
4
+
5
+import org.springframework.boot.CommandLineRunner;
6
+import org.springframework.boot.SpringApplication;
7
+import org.springframework.boot.autoconfigure.SpringBootApplication;
8
+import org.springframework.context.ApplicationContext;
9
+import org.springframework.context.annotation.Bean;
10
+
11
+@SpringBootApplication
12
+public class Application {
13
+
14
+    public static void main(String[] args) {
15
+        SpringApplication.run(Application.class, args);
16
+    }
17
+
18
+    @Bean
19
+    public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
20
+        return args -> {
21
+
22
+            System.out.println("Let's inspect the beans provided by Spring Boot:");
23
+
24
+            String[] beanNames = ctx.getBeanDefinitionNames();
25
+            Arrays.sort(beanNames);
26
+            for (String beanName : beanNames) {
27
+                System.out.println(beanName);
28
+            }
29
+
30
+        };
31
+    }
32
+
33
+}

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

@@ -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 View File

@@ -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")
15
+    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
16
+        return new Greeting(counter.incrementAndGet(),
17
+                String.format(template, name));
18
+    }
19
+}

+ 14
- 0
initial/src/main/java/hello/HelloController.java View File

@@ -0,0 +1,14 @@
1
+//package hello;
2
+//
3
+//import org.springframework.web.bind.annotation.RestController;
4
+//import org.springframework.web.bind.annotation.RequestMapping;
5
+//
6
+//@RestController
7
+//public class HelloController {
8
+//
9
+//    @RequestMapping("/")
10
+//    public String index() {
11
+//        return "Greetings from Spring Boot!";
12
+//    }
13
+//
14
+//}