JavaIntermediate#spring

What is the difference between @RequestParam, @PathVariable, and @RequestBody?

@RequestParam extracts query string parameters, @PathVariable extracts values embedded in the URL path, and @RequestBody deserializes the HTTP request body (typically JSON) into a Java object.

Example
@GetMapping("/users/{id}")
User getUser(@PathVariable Long id, @RequestParam(required=false) String filter) { ... }
@PostMapping("/users")
User create(@RequestBody User user) { ... }

Related Questions

1
JavaIntermediate#spring

What are Spring bean scopes?

Open
2
JavaIntermediate#puzzle#operators

What does this print? int x = 5; System.out.println(x++ + ++x);

Open
3
JavaBeginner#puzzle#strings

What is the output of this code? String s1 = "abc"; String s2 = "abc"; String s3 = new String("abc"); System.out.println(s1 == s2); System.out.println(s1 == s3);

Open