Sobes.tech
Junior — Middle

What alternative annotations, besides @Controller, can be used to define the controller layer in Spring?

sobes.tech AI

Answer from AI

In Spring, to define a controller layer, besides the @Controller annotation, you can use the following alternatives:

  • @RestController — combines @Controller and @ResponseBody, automatically serializing returned objects into JSON or XML, which is convenient for creating REST APIs.
  • @RequestMapping — used to specify URL routes, but does not itself define a controller; it is usually used together with @Controller or @RestController.

Therefore, if you need to create a REST controller, it is preferable to use @RestController.

What alternative annotations, besides @Controller… - sobes.tech