Kaynağa Gözat

Edit README and update test script

Chris Beams 13 yıl önce
ebeveyn
işleme
4e314e8de6
3 değiştirilmiş dosya ile 15 ekleme ve 10 silme
  1. 1
    0
      .gitignore
  2. 13
    9
      README.md
  3. 1
    1
      test/run.sh

+ 1
- 0
.gitignore Dosyayı Görüntüle

10
 target
10
 target
11
 dependency-reduced-pom.xml
11
 dependency-reduced-pom.xml
12
 *.sublime-*
12
 *.sublime-*
13
+/scratch

+ 13
- 9
README.md Dosyayı Görüntüle

57
 
57
 
58
     <groupId>org.springframework</groupId>
58
     <groupId>org.springframework</groupId>
59
     <artifactId>gs-rest-service</artifactId>
59
     <artifactId>gs-rest-service</artifactId>
60
-    <version>0.0.1-SNAPSHOT</version>
60
+    <version>1.0</version>
61
 
61
 
62
     <parent>
62
     <parent>
63
         <groupId>org.springframework.bootstrap</groupId>
63
         <groupId>org.springframework.bootstrap</groupId>
149
     "content": "Hello, World!"
149
     "content": "Hello, World!"
150
 }
150
 }
151
 ```
151
 ```
152
-    
152
+
153
 The `id` field is a unique identifier for the greeting, and `content` is the textual representation of the greeting.
153
 The `id` field is a unique identifier for the greeting, and `content` is the textual representation of the greeting.
154
 
154
 
155
 To model the greeting representation, we’ll create a representation class:
155
 To model the greeting representation, we’ll create a representation class:
164
     private final String content;
164
     private final String content;
165
 
165
 
166
     public Greeting(long id, String content) {
166
     public Greeting(long id, String content) {
167
-    this.id = id;
168
-    this.content = content;
167
+        this.id = id;
168
+        this.content = content;
169
     }
169
     }
170
 
170
 
171
     public long getId() {
171
     public long getId() {
172
-    return id;
172
+        return id;
173
     }
173
     }
174
 
174
 
175
     public String getContent() {
175
     public String getContent() {
176
-    return content;
176
+        return content;
177
     }
177
     }
178
 }
178
 }
179
 ```
179
 ```
209
 }
209
 }
210
 ```
210
 ```
211
 
211
 
212
-The key difference between a human-facing controller and a REST endpoint controller is in how the response is created. Rather than rely on a view (such as JSP) to render model data in HTML, an endpoint controller simply returns the data to be written directly to the body of the response.
212
+The key difference between a human-facing controller and a REST endpoint controller is in how the response is created. Rather than rely on a view (such as a [JSP](/understanding/JSP)) to render model data in HTML, an endpoint controller simply returns the data to be written directly to the body of the response.
213
 
213
 
214
-The magic is in the [`@ResponseBody`](http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/web/bind/annotation/ResponseBody.html) annotation. `@ResponseBody` tells Spring MVC to not render a model into a view, but rather to write the returned object into the response body. It does this by using one of Spring's message converters. Because Jackson 2 is in the classpath, this means that [`MappingJackson2HttpMessageConverter`](http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.html) will handle the conversion of Greeting to JSON if the request's `Accept` header specifies that JSON should be returned.
214
+The magic is in the [`@ResponseBody`](http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/web/bind/annotation/ResponseBody.html) annotation. `@ResponseBody` tells Spring MVC to not render a model into a view, but rather to write the returned object into the response body. It does this by using one of Spring's message converters. Because Jackson 2 is on the classpath, Spring's [`MappingJackson2HttpMessageConverter`](http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.html) is automatically chosen to convert the Greeting instance to JSON.
215
 
215
 
216
 
216
 
217
 Creating an executable main class
217
 Creating an executable main class
251
 
251
 
252
 `pom.xml`
252
 `pom.xml`
253
 ```xml
253
 ```xml
254
+<properties>
255
+    <start-class>hello.HelloWorldConfiguration</start-class>
256
+</properties>
257
+
254
 <build>
258
 <build>
255
     <plugins>
259
     <plugins>
256
         <plugin>
260
         <plugin>
271
 
275
 
272
 Now you can run it from the jar as well, and distribute that as an executable artifact:
276
 Now you can run it from the jar as well, and distribute that as an executable artifact:
273
 ```
277
 ```
274
-$ java -jar target/gs-rest-service-1.0-SNAPSHOT.jar
278
+$ java -jar target/gs-rest-service-1.0.jar
275
 
279
 
276
 ... service comes up ...
280
 ... service comes up ...
277
 ```
281
 ```

+ 1
- 1
test/run.sh Dosyayı Görüntüle

1
 cd $(dirname $0)
1
 cd $(dirname $0)
2
 cd ../complete
2
 cd ../complete
3
 mvn package
3
 mvn package
4
-java -jar target/gs-rest-service-complete-1.0-SNAPSHOT.jar &
4
+java -jar target/gs-rest-service-complete-1.0.jar &
5
 PID=$!
5
 PID=$!
6
 sleep 3
6
 sleep 3
7
 curl -s http://localhost:8080/hello-world > target/actual.json
7
 curl -s http://localhost:8080/hello-world > target/actual.json