Ben Blinebury 6 年前
父节点
当前提交
0393afe748

+ 1
- 1
complete/src/main/java/hello/Greeting.java 查看文件

@@ -2,7 +2,7 @@ package hello;
2 2
 
3 3
 public class Greeting {
4 4
 
5
-    private final long id;
5
+    private final Long id;
6 6
     private final String content;
7 7
 
8 8
     public Greeting(long id, String content) {

+ 1
- 0
complete/src/test/java/hello/GreetingControllerTests.java 查看文件

@@ -33,6 +33,7 @@ import org.springframework.test.web.servlet.MockMvc;
33 33
 @AutoConfigureMockMvc
34 34
 public class GreetingControllerTests {
35 35
 
36
+
36 37
     @Autowired
37 38
     private MockMvc mockMvc;
38 39
 

+ 59
- 0
pom.xml 查看文件

@@ -0,0 +1,59 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+    <modelVersion>4.0.0</modelVersion>
5
+
6
+    <groupId>org.springframework</groupId>
7
+    <artifactId>gs-rest-service</artifactId>
8
+    <version>0.1.0</version>
9
+
10
+    <parent>
11
+        <groupId>org.springframework.boot</groupId>
12
+        <artifactId>spring-boot-starter-parent</artifactId>
13
+        <version>2.0.3.RELEASE</version>
14
+    </parent>
15
+
16
+    <dependencies>
17
+        <dependency>
18
+            <groupId>org.springframework.boot</groupId>
19
+            <artifactId>spring-boot-starter-web</artifactId>
20
+        </dependency>
21
+        <dependency>
22
+            <groupId>org.springframework.boot</groupId>
23
+            <artifactId>spring-boot-starter-test</artifactId>
24
+            <scope>test</scope>
25
+        </dependency>
26
+        <dependency>
27
+            <groupId>com.jayway.jsonpath</groupId>
28
+            <artifactId>json-path</artifactId>
29
+            <scope>test</scope>
30
+        </dependency>
31
+    </dependencies>
32
+
33
+    <properties>
34
+        <java.version>1.8</java.version>
35
+    </properties>
36
+
37
+
38
+    <build>
39
+        <plugins>
40
+            <plugin>
41
+                <groupId>org.springframework.boot</groupId>
42
+                <artifactId>spring-boot-maven-plugin</artifactId>
43
+            </plugin>
44
+        </plugins>
45
+    </build>
46
+
47
+    <repositories>
48
+        <repository>
49
+            <id>spring-releases</id>
50
+            <url>https://repo.spring.io/libs-release</url>
51
+        </repository>
52
+    </repositories>
53
+    <pluginRepositories>
54
+        <pluginRepository>
55
+            <id>spring-releases</id>
56
+            <url>https://repo.spring.io/libs-release</url>
57
+        </pluginRepository>
58
+    </pluginRepositories>
59
+</project>

+ 12
- 0
src/main/java/hello/Application.java 查看文件

@@ -0,0 +1,12 @@
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
+        SpringApplication.run(Application.class, args);
11
+    }
12
+}

+ 21
- 0
src/main/java/hello/Greeting.java 查看文件

@@ -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
+
9
+    public Long getId() {
10
+        return id;
11
+    }
12
+
13
+    public String getContent() {
14
+        return content;
15
+    }
16
+
17
+    public Greeting(Long id, String content) {
18
+        this.id = id;
19
+        this.content = content;
20
+    }
21
+}

+ 20
- 0
src/main/java/hello/GreetingController.java 查看文件

@@ -0,0 +1,20 @@
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
+import java.util.concurrent.atomic.AtomicLong;
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(), String.format(template, name));
17
+    }
18
+
19
+
20
+}