Spring Annotations Overview
Spring Annotations Overview
Overview
Overview of annotations like
@RequestBody, @PathVariable,
@PostMapping, and more
@RequestBody
• Binds the HTTP request body to a Java object.
• Typically used for POST, PUT, and PATCH
requests.
@PathVariable
• Binds a URI template variable to a method
parameter.
• Commonly used in RESTful API for URL
variables.
@PostMapping
• A shorthand for @RequestMapping(method =
RequestMethod.POST).
• Used to map HTTP POST requests to a
method.
@GetMapping
• A shorthand for @RequestMapping(method =
RequestMethod.GET).
• Used to map HTTP GET requests to a method.
@RestController
• Combines @Controller and @ResponseBody,
used for REST APIs.
• All methods are automatically annotated with
@ResponseBody.
@Validated
• Triggers validation of method parameters or
bean fields.
• Works with JSR-303/JSR-380 annotations like
@NotNull, @Size.
@RequestMapping
• General-purpose annotation for mapping
HTTP requests to methods.
• Can be used for all HTTP verbs (GET, POST,
etc.).
@RequiredArgsConstructor
• A Lombok annotation that generates a
constructor for final fields.
• Simplifies dependency injection in Spring
applications.