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
1
2
3
4
5
6
7
@RestControllerpublic 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.