Browse Source

Upgrade from @Controller/@ResponseBody to @RestController

Resolves #22
Greg Turnquist 10 years ago
parent
commit
97f4d02b4f
1 changed files with 4 additions and 6 deletions
  1. 4
    6
      complete/src/main/java/hello/GreetingController.java

+ 4
- 6
complete/src/main/java/hello/GreetingController.java View File

@@ -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
+}