|
|
@@ -118,22 +118,21 @@ Now you can create a web controller for a simple web application.
|
|
118
|
118
|
```java
|
|
119
|
119
|
package hello;
|
|
120
|
120
|
|
|
121
|
|
-import org.springframework.stereotype.Controller;
|
|
|
121
|
+import org.springframework.web.bind.annotation.RestController;
|
|
122
|
122
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
123
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
|
124
|
123
|
|
|
125
|
|
-@Controller
|
|
|
124
|
+@RestController
|
|
126
|
125
|
public class HelloController {
|
|
127
|
126
|
|
|
128
|
127
|
@RequestMapping("/")
|
|
129
|
|
- public @ResponseBody String index() {
|
|
|
128
|
+ public String index() {
|
|
130
|
129
|
return "Greetings from Spring Boot!";
|
|
131
|
130
|
}
|
|
132
|
131
|
|
|
133
|
132
|
}
|
|
134
|
133
|
```
|
|
135
|
134
|
|
|
136
|
|
-The class is flagged as a `@Controller`, meaning it's ready for use by Spring MVC to handle web requests. `@RequestMapping` maps `/` to the `index()` method. When invoked from a browser or using curl on the command line, the method returns pure text thanks to the `@ResponseBody` annotation.
|
|
|
135
|
+The class is flagged as a `@RestController`, meaning it's ready for use by Spring MVC to handle web requests. `@RequestMapping` maps `/` to the `index()` method. When invoked from a browser or using curl on the command line, the method returns pure text. That's because `@RestController` combines `@Controller` and `@ResponseBody`, two annotations that results in web requests returning data rather than a view.
|
|
137
|
136
|
|
|
138
|
137
|
Create an Application class
|
|
139
|
138
|
---------------------------
|
|
|
@@ -473,11 +472,10 @@ On top of that, Spring Boot also has Groovy support, allowing you to build Sprin
|
|
473
|
472
|
Create a new file called **app.groovy** and put the following code in it:
|
|
474
|
473
|
|
|
475
|
474
|
```groovy
|
|
476
|
|
-@Controller
|
|
|
475
|
+@RestController
|
|
477
|
476
|
class ThisWillActuallyRun {
|
|
478
|
477
|
|
|
479
|
478
|
@RequestMapping("/")
|
|
480
|
|
- @ResponseBody
|
|
481
|
479
|
String home() {
|
|
482
|
480
|
return "Hello World!"
|
|
483
|
481
|
}
|