@RequestBody
- Description: Binds the body of an HTTP request to a Java object, typically used in POST or PUT requests.
- Example:
@PostMapping("/add")
public ResponseEntity addEntity(@RequestBody MyEntity entity) {
// logic
}
@RequestParam
- Description: Extracts query parameters from the URL.
- Example:
@GetMapping("/search")
public ResponseEntity search(@RequestParam String query) {
// logic
}
@PathVariable
- Description: Captures values from the URI path and binds them to method parameters.
- Example :
@GetMapping("/items/{id}")
public ResponseEntity getItem(@PathVariable Long id) {
// logic
}
@Validated
-
Description: Enables validation for a method parameter or
bean, used in combination with validation annotations like
@NotNull
,@Size
, etc. - Example:
@Valid
- Description: Triggers validation for the annotated object, typically a request body.
- Example:
@ModelAttribute
- Description: Binds request parameters to a model object, commonly used in forms.
- Example:
@PostMapping("/form")
@CookieValue
- Description: Binds HTTP cookie values to a method parameter.
- Example:
@GetMapping("/get-cookie")>
public String getCookieValue(@CookieValue String sessionId) {
// logic
}
0 Comments