Sobes.tech
Junior — Middle

Can you list annotations for controllers that contain additional keywords or parameters?

sobes.tech AI

Answer from AI

In Spring MVC and Spring Boot, controllers use annotations that can contain additional parameters and keywords to configure behavior:

  • @RequestMapping — the basic annotation for specifying the path, HTTP methods (method), request parameters (params), headers (headers), the content type consumed (consumes), and produced (produces).

    @RequestMapping(value = "/users", method = RequestMethod.GET, produces = "application/json")
    public List<User> getUsers() { ... }
    
  • @GetMapping, @PostMapping, @PutMapping, @DeleteMapping, @PatchMapping — specialized shortcuts for @RequestMapping with specified HTTP methods. They also support parameters like value, path, params, headers, consumes, produces.

    @PostMapping(value = "/users", consumes = "application/json")
    public ResponseEntity<?> createUser(@RequestBody User user) { ... }
    
  • @RestController — combines @Controller and @ResponseBody, has no parameters but influences controller behavior.

  • @CrossOrigin — for configuring CORS, contains parameters like origins, methods, allowedHeaders, etc.

Thus, key parameters are usually related to routing, HTTP methods, data types, and headers.

Can you list annotations for controllers that contain… - sobes.tech