Sobes.tech
Junior — Middle

What annotations are available for defining controllers in your framework?

sobes.tech AI

Answer from AI

In Java frameworks such as Spring, the following annotations are used to define controllers:

  • @Controller — indicates a class as a controller that handles HTTP requests and returns views.
  • @RestController — a specialized annotation combining @Controller and @ResponseBody, used for creating RESTful web services that return data in JSON or XML format.

Example:

@RestController
public class MyController {
    @GetMapping("/hello")
    public String sayHello() {
        return "Hello, World!";
    }
}
What annotations are available for defining… - sobes.tech