java / beginner
Snippet
Simple REST Controller
A RestController is the entry point for web requests in Spring. It combines @Controller and @ResponseBody, meaning the return value is sent directly to the web response.
snippet.java
1
2
3
4
5
6
7
8
9
@RestController@RequestMapping("/api")public class HelloController {@GetMapping("/hello")public String sayHello() {return "Hello Spring!";}
spring
Breakdown
1
@RestController
Marks the class as a web controller that returns data instead of a view.
2
@GetMapping("/hello")
Maps HTTP GET requests to the /api/hello URL to this method.