0 day streak
java / beginner
Snippet

Creating a Simple REST Controller

The @RestController annotation marks a class as a web controller where every method returns data directly to the HTTP response body instead of rendering a template.

snippet.java
java
1
2
3
4
5
6
7
@RestController
public class WelcomeController {
@GetMapping("/welcome")
public String welcome() {
return "Welcome to Spring Boot!";
}
}
spring
Breakdown
1
@RestController
Combines @Controller and @ResponseBody, meaning data is returned directly.
2
@GetMapping("/welcome")
Maps HTTP GET requests to the specified path.