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@RequestMappingwith specified HTTP methods. They also support parameters likevalue,path,params,headers,consumes,produces.@PostMapping(value = "/users", consumes = "application/json") public ResponseEntity<?> createUser(@RequestBody User user) { ... } -
@RestController— combines@Controllerand@ResponseBody, has no parameters but influences controller behavior. -
@CrossOrigin— for configuring CORS, contains parameters likeorigins,methods,allowedHeaders, etc.
Thus, key parameters are usually related to routing, HTTP methods, data types, and headers.