Junior — Middle
Have you participated in API development using the @RestController annotation in Spring?
sobes.tech AI
Answer from AI
Yes, the @RestController annotation in Spring is used for creating RESTful web services. It combines @Controller and @ResponseBody, allowing controller methods to automatically return data in JSON or XML format. For example:
@RestController
public class UserController {
@GetMapping("/users/{id}")
public User getUser(@PathVariable Long id) {
// logic to get user by id
return userService.findById(id);
}
}
This controller handles HTTP requests and returns data directly to the client without additional serialization.