← All tutorials

GoCareerGo Tutorials

Spring Boot Tutorial

Auto-configuration, REST APIs, JPA, AOP, caching, microservices and Spring Cloud.

@RestController

A convenience annotation that combines @Controller and @ResponseBody — every method's return value is serialized straight to the HTTP response body (usually JSON).

@RestController
@RequestMapping("/api/products")
public class ProductController {

    @GetMapping
    public List<Product> getAll() {
        return productService.findAll(); // auto-serialized to JSON
    }
}