瀏覽代碼

Upgrade from @Controller/@ResponseBody to @RestController

Resolves #22
Greg Turnquist 10 年之前
父節點
當前提交
97f4d02b4f
共有 1 個文件被更改,包括 4 次插入6 次删除
  1. 4
    6
      complete/src/main/java/hello/GreetingController.java

+ 4
- 6
complete/src/main/java/hello/GreetingController.java 查看文件

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